template_id=$template_id; //$r=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select name from ecmdocumenttemplates where id='".$template_id."'")); //$query = $db->executeQuery(query("select name from ecmdocumenttemplates where id='".$template_id."'")); $row = $db->fetchFirstRow("select name from ecmdocumenttemplates where id='".$template_id."'"); $focus->template_name=$row['name']; $focus->setTemplate(); $focus->number=$focus->generateNumber(); $focus->document_no=$focus->formatNumber(); $focus->currency_id="PLN"; $focus->ecmlanguage="pl_pl"; $focus->status="s10"; $focus->type="sales_order"; $focus->modified_user_id="d09b87cf-efff-2f7c-a859-4ba38402488f"; $focus->created_by="d09b87cf-efff-2f7c-a859-4ba38402488f"; $pr=$order['Order-Lines']; $x = "ok"; include_once("modules/Accounts/Account.php"); //$ww=$GLOBALS['db']->query("select count(*) as c from accounts where b2clogin ='".$order['Order-Parties']['Buyer']['Login']."' and deleted='0'"); //$ww=$GLOBALS['db']->query("select count(*) as c from accounts where `id` ='".$order['Order-Parties']['Buyer']['Login']."' and deleted='0'"); $row = $db->fetchFirstRow("select count(*) as c from accounts where `id` ='".$order['Order-Parties']['Buyer']['Login']."' and deleted='0'"); //$rr=$GLOBALS['db']->fetchByAssoc($ww); $focus->parent_id="getmir"; $focus->description=iconv("ISO-8859-2","UTF-8",$order['Order-Parties']['Buyer']['Description']); // if($rr['c']==0){ // $account=new Account(); $account->ownership="getmir"; // $account->name=iconv("ISO-8859-2","UTF-8",$order['Order-Parties']['Buyer']['Name']); // $account->b2clogin=iconv("ISO-8859-2","UTF-8",$order['Order-Parties']['Buyer']['Login']); // $account->billing_address_street=iconv("ISO-8859-2","UTF-8",$order['Order-Parties']['Buyer']['StreetAndNumber']); // $account->billing_address_postalcode=iconv("ISO-8859-2","UTF-8",$order['Order-Parties']['Buyer']['PostalCode']); // $account->billing_address_city=iconv("ISO-8859-2","UTF-8",$order['Order-Parties']['Buyer']['CityName']); // $account->shipping_address_street=iconv("ISO-8859-2","UTF-8",$order['Order-Parties']['DeliveryPoint']['StreetAndNumber']); // $account->shipping_address_postalcode=iconv("ISO-8859-2","UTF-8",$order['Order-Parties']['DeliveryPoint']['PostalCode']); // $account->shipping_address_city=iconv("ISO-8859-2","UTF-8",$order['Order-Parties']['DeliveryPoint']['CityName']); // $focus->parent_id=create_guid_2(); // $GLOBALS['db']->query("insert into accounts set id='".$focus->parent_id."',name='".$account->name."',billing_address_street='".$account->billing_address_street."',billing_address_postalcode='".$account->billing_address_postalcode."',billing_address_city='".$account->billing_address_city."',shipping_address_street='".$account->shipping_address_street."',shipping_address_postalcode='".$account->shipping_address_postalcode."',shipping_address_city='".$account->shipping_address_city."', b2clogin='".$account->b2clogin."'"); // } // else{ //$w=$GLOBALS['db']->query("select id from accounts where b2clogin = '".$order['Order-Parties']['Buyer']['Login']."' and deleted='0'"); //$w=$GLOBALS['db']->query("select `id` from `accounts` where `id` = '".$order['Order-Parties']['Buyer']['Login']."' and `deleted`='0'"); $row = $db->fetchFirstRow("select `id` from `accounts` where `id` = '".$order['Order-Parties']['Buyer']['Login']."' and `deleted`='0'"); //$r=$GLOBALS['db']->fetchByAssoc($w); $account=new Account(); //update account, maybe sth. change // $GLOBALS['db']->query("update accounts set name='".$account->name."',billing_address_street='".$account->billing_address_street."',billing_address_postalcode='".$account->billing_address_postalcode."',billing_address_city='".$account->billing_address_city."'"."',shipping_address_street='".$account->shipping_address_street."',shipping_address_postalcode='".$account->shipping_address_postalcode."',shipping_address_city='".$account->shipping_address_city."'where id='".$r['id']."'"); // $account->retrieve($r['id']); $focus->parent_id=$row['id']; //} $focus->assigned_user_id="d09b87cf-efff-2f7c-a859-4ba38402488f"; $focus->register_date=$order['Order-Header']['OrderDate']; $focus->delivery_date=$order['Order-Header']['ExpectedDeliveryDate']; //$focus->supplier_code=3442; $focus->order_no=$order['Order-Header']['OrderNumber']; $focus->ecmlanguage="pl_pl"; $focus->ecmpaymentcondition_id=$order['Order-Parties']['Buyer']['PaymentConditionId']; $focus->parent_name=$row["name"];//$account->name; $focus->parent_address_street=$a;//$account->shipping_address_street; $focus->parent_address_city=$b;//$account->shipping_address_city; $focus->parent_address_postalcode=$c;//$account->shipping_address_postalcode; $focus->parent_address_country=$d;//$account->shipping_address_country; $ra=array(); $total=0; if(count($pr)>0){ foreach($pr as $prod){ $product_id=""; //$w=$GLOBALS['db']->query("select id as ecmproduct_id from ecmproducts where code='".$prod['Line']['Line-Item']['CODE']."' and deleted='0' and code NOT LIKE '%_w' and code NOT LIKE '%_z' and code NOT LIKE '%_W' and code NOT LIKE '%_Z'"); //$w=$GLOBALS['db']->query("select `id` as `ecmproduct_id` from `ecmproducts` where `id`='".$prod['Line']['Line-Item']['CODE']."' and `deleted`='0' and `code` NOT LIKE '%_w' and `code` NOT LIKE '%_z' and `code` NOT LIKE '%_W' and `code` NOT LIKE '%_Z'"); $row = $db->fetchFirstRow("select `id` as `ecmproduct_id` from `ecmproducts` where `id`='".$prod['Line']['Line-Item']['CODE']."' and `deleted`='0' and `code` NOT LIKE '%_w' and `code` NOT LIKE '%_z' and `code` NOT LIKE '%_W' and `code` NOT LIKE '%_Z'"); // $r=$GLOBALS['db']->fetchByAssoc($w); $product_id=$row['ecmproduct_id']; $wp=$GLOBALS['db']->query("select * from `ecmproducts` where `id`='".$product_id."'"); $rppp=$GLOBALS['db']->fetchByAssoc($wp); $product_code=$rppp['code']; $product_name=$rppp['name']; $vat_id=$rppp['vat_id']; $vat_name=$rppp['vat_name']; $vat_value=$rppp['vat_value']; $return_array['id'] = $product_id; $return_array['code'] = $product_code; $return_array['name'] = $product_name; $return_array['quantity'] = $prod['Line']['Line-Item']['OrderedQuantity']; $return_array['price'] = $prod['Line']['Line-Item']['OrderedUnitNetPrice']; $return_array['discount'] = 0; $return_array['total'] = $prod['Line']['Line-Item']['OrderedQuantity']*$prod['Line']['Line-Item']['OrderedUnitNetPrice']; $return_array['unit_id'] = 1; $return_array['unit_name'] = 'szt.'; $return_array['vat_id'] = $vat_id; $return_array['vat_name'] = $vat_name; $return_array['vat_value'] = $vat_value; $return_array['currency_id'] = 'PLN'; $return_array['recipient_code'] = $prod['Line']['Line-Item']['BuyerItemCode']; $total+=$return_array['quantity']*$return_array['price']*(1+$vat_value/100); $ra[]=$return_array; } } $focus->position_list = $ra; $return_id=$focus->save_from_shop($presta, $user); $GLOBALS['db']->query("update `ecmsales` set `total`='".$total."' where `id`='".$return_id."'"); return $return_id; //return print_r(mysql_error()."mm", true); } } } catch(Exception $e) {} } return $y; } $order_lines = array(); $line= array( 'Line' => array( 'Line-Item' => array( 'LineNumber' => 1, 'CODE' => 33, 'EAN' => '', 'BuyerItemCode' => '', 'SupplierItemCode' => '', 'ItemDescription' => "produkt", 'ItemType' => 'CU', 'OrderedQuantity' => "1", 'OrderedUnitPacksize' => 1, 'UnitOfMeasure' => 'PCE', 'OrderedUnitNetPrice' => 99, 'PackageNumber' => '', ), ), ); $order_lines[] = $line; $order = array(); $order['Order-Summary'] = array( 'TotalLines' => 1-1, 'TotalOrderedAmount' => "5000", ); $order['Order-Lines'] = $order_lines; // ilosc wierszy w zamowieniu // echo print_r($order); //exit; $order['Order-Parties']['Buyer']['Login'] = "777"; // login uzytkownika $order['Order-Parties']['Buyer']['Description'] = ""; // opis $order['Order-Header']['OrderDate'] = date("Y-m-d"); $order['Order-Header']['ExpectedDeliveryDate'] = date("Y-m-d"); $order['Order-Header']['OrderNumber'] = "brak"; // numer zamowienia $order['Order-Parties']['Buyer']['PaymentConditionId'] = "23d19aa9-d63a-dd99-568c-4dff0bbc7f40"; // 7 dni na zaplate $getReference = "HKKMLOPMX"; $order['Order-Header']['Presta'] = $getReference; ?>