117 lines
4.3 KiB
PHP
117 lines
4.3 KiB
PHP
<?php
|
|
require_once('modules/EcmAccounts/Account.php');
|
|
require_once('modules/EcmInvoiceOutOlds/EcmInvoiceOutOld.php');
|
|
require_once('modules/EcmSales/EcmSale.php');
|
|
|
|
function createInvoiceFromWz($id) {
|
|
$i = new EcmInvoiceOutOld();
|
|
|
|
//create products array
|
|
$r = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("SELECT * FROM ecmstockdocouts WHERE id='" . $id . "'"));
|
|
$a = new Account();
|
|
$a->retrieve($r['parent_id']);
|
|
|
|
$i->parent_id = $r['parent_id'];
|
|
$i->parent_name = $r['parent_name'];
|
|
$i->parent_address_street = $r['parent_address_street'];
|
|
$i->parent_address_city = $r['parent_address_city'];
|
|
$i->parent_address_postalcode = $r['parent_address_postalcode'];
|
|
$i->parent_address_country = $r['parent_address_country'];
|
|
$i->to_nip = $a->to_vatid;
|
|
$i->ecmpaymentcondition_id = $a->ecmpaymentcondition_id;
|
|
$i->supplier_code = $a->supplier_code;
|
|
$pc = new EcmPaymentCondition();
|
|
$pc->retrieve($a->ecmpaymentcondition_id);
|
|
$i->ecmpaymentcondition_name = $pc->name;
|
|
$i->payment_date=$GLOBALS['timedate']->to_display_date(date("Y-m-d",mktime()+3600*24*$pc->days));
|
|
|
|
$s = new EcmSale();
|
|
$s->retrieve($r['so_id']);
|
|
|
|
//delivery address
|
|
$i->parent_shipping_address_name = $s->parent_shipping_address_name;
|
|
$i->parent_shipping_address_street = $s->parent_shipping_address_street;
|
|
$i->parent_shipping_address_city = $s->parent_shipping_address_city;
|
|
$i->parent_shipping_address_postalcode = $s->parent_shipping_address_postalcode;
|
|
$i->parent_shipping_address_country = $s->parent_shipping_address_country;
|
|
|
|
$i->template_id = $r['template_id'];
|
|
$i->template_name = $r['template_name'];
|
|
$i->parent_contact_name = $r['parent_contact_name'];
|
|
$i->parent_contact_title = $r['parent_contact_title'];
|
|
$i->order_no = $r['order_no'];
|
|
$i->contact_id = $r['contact_id'];
|
|
$i->name = $r['name'];
|
|
$i->register_date=$GLOBALS['timedate']->to_display_date(date("Y-m-d"));
|
|
$i->sell_date=$GLOBALS['timedate']->to_display_date(date("Y-m-d"));
|
|
$i->wz_id = $id;
|
|
$i->status="accepted";
|
|
$i->type = "normal";
|
|
$i->assigned_user_id='c054ae2d-7d94-5a74-28a0-5236e3d1493e';
|
|
$i->created_by='c054ae2d-7d94-5a74-28a0-5236e3d1493e';
|
|
$i->modified_user_id='c054ae2d-7d94-5a74-28a0-5236e3d1493e';
|
|
$i->pdf_type=$s->$s->pdf_type;
|
|
$i->currency_id=$s->currency_id;
|
|
|
|
unset($s);
|
|
|
|
|
|
//set possition list
|
|
$pl = array ();
|
|
|
|
$res = $GLOBALS ['db']->query ( "SELECT * FROM ecmstockdocoutitems WHERE ecmstockdocout_id ='" . $id . "' order by position" );
|
|
|
|
global $app_list_strings;
|
|
|
|
while ( $r = $GLOBALS ['db']->fetchByAssoc ( $res ) ) {
|
|
|
|
$t = $GLOBALS ['db']->fetchByAssoc ( $GLOBALS ['db']->query ( "SELECT unit_id FROM ecmproducts WHERE id='" . $r['ecmproduct_id'] . "'" ) );
|
|
|
|
$subprice = $r['selling_price'];
|
|
$subtotal = $r['quantity'] * $subprice;
|
|
$vat = $subtotal * ($r['ecmvat_value'] / 100);
|
|
$total = $subtotal + $vat;
|
|
$price = $total / $r['quantity'];
|
|
|
|
$position = array ();
|
|
|
|
$position ['iid'] = create_guid ();
|
|
$position ['code'] = $r ['code'];
|
|
$position ['name'] = $r ['name'];
|
|
$position ['id'] = $r ['ecmproduct_id'];
|
|
$position ['quantity'] = $r ['quantity'];
|
|
// calculate currency
|
|
$position ['startprice'] = $r ['selling_price'];
|
|
$position['subprice'] = $subprice;
|
|
$position['price'] = $price;
|
|
$position['subtotal'] = $subtotal;
|
|
$position['total'] = $total;
|
|
|
|
|
|
$position ['discount'] = $r ['discount'];
|
|
$position ['unit_id'] = $t['unit_id'];
|
|
$position ['unit_name'] = $app_list_strings['ecmproducts_unit_dom'][$t['unit_id']];
|
|
$position ['vat_id'] = $r ['ecmvat_id'];
|
|
$position ['vat_name'] = $r ['ecmvat_name'];
|
|
$position ['vat_value'] = $r ['ecmvat_value'];
|
|
$position ['category_id'] = $r ['ecmproductcategory_id'];
|
|
$position ['currency_id'] = $r ['currency_id'];
|
|
$position ['currency_name'] = $r ['currency_name'];
|
|
$position ['recipient_code'] = $r ['recipient_code'];
|
|
$position ['type'] = $t ['type'];
|
|
$position ['parent_doc_id'] = $r ['ecmstockdocout_id'];
|
|
$position ['parent_doc_type'] = 'EcmStockDocOut';
|
|
$position ['parent_doc_item_id'] = $r ['id'];
|
|
$position ['temp_item_id'] = create_guid ();
|
|
$position ['temp_date'] = date ( "Y-m-d H:i:s" );
|
|
|
|
$pl [] = $position;
|
|
}
|
|
|
|
$i->position_list = $pl;
|
|
|
|
|
|
|
|
$i->save();
|
|
}
|
|
?>
|