decode(htmlspecialchars_decode($_POST['p_' . $i])); $_POST['p_' . $i] = ''; $i++; } $_POST = $json->decode(htmlspecialchars_decode($_POST['otherFormData'])); $_POST['position_list'] = $pll; $_REQUEST = $_POST; require_once("modules/EcmReceipts/EcmReceipt.php"); require_once('include/formbase.php'); $focus = new EcmReceipt(); if (isset($_POST['record']) && $_POST['record'] != '') { $focus->retrieve($_POST['record']); //$focus->id = $_POST['record']; } if (isset($focus->id) && $focus->id != '') { $_POST['email_id'] = $focus->email_id; } else { $new_invoice = true; } if (!$focus->ACLAccess('Save')) { ACLController::displayNoAccess(true); sugar_cleanup(true); } //if (!empty($_POST['assigned_user_id']) && ($focus->assigned_user_id != $_POST['assigned_user_id']) && ($_POST['assigned_user_id'] != $current_user->id)) { // $check_notify = true; //} else { // $check_notify = false; //} $check_notify = false; //$json = getJSONobj(); //$wi = $json->decode(htmlspecialchars_decode($_POST['work_items'])); //$focus->work_items = $wi; //echo var_export($_POST['document_no'], true);exit; // ~ // array ( // 'module' => 'EcmReceipts', // 'action' => 'Save', // 'record' => '', // 'to_pdf' => '1', // 'cache' => 'fromJava', // 'isDuplicate' => 'false', // 'return_module' => 'EcmReceipts', // 'return_action' => 'DetailView', // 'return_id' => '', // 'contact_role' => '', // 'relate_to' => 'EcmReceipts', // 'relate_id' => '', // 'offset' => '1', // 'position_list' => // array ( // 0 => // array ( // 'index' => '1', // 'code' => '020099', // 'id' => '7a571024-02c2-7c7c-2429-501aa098386e', // 'category_id' => '', // 'currency_id' => 'undefined', // 'currency_symbol' => 'undefined', // 'ecmstockdocout_id' => '', // 'temp_item_id' => '', // 'temp_date' => '', // 'type' => '', // 'parent_doc_id' => '', // 'parent_doc_type' => '', // 'parent_doc_item_id' => '', // 'name' => 'IV53 TŁOK 82MM ACX83D', // 'quantity' => 1, // 'startprice' => 1, // 'pricehelper' => 1.23, // 'discount' => 0, // 'vat_value' => '23.00', // 'vat_id' => '9ec174d1-db5e-8db6-9195-4e6e4a041e40', // 'subprice' => 1, // 'price' => 1.23, // 'unit_id' => 'undefined', // 'unit_name' => 'undefined', // 'subtotal' => 1, // 'total' => 1.23, // 'stock' => 3, // 'reserved' => '1', // 'parent_doc_rq' => '', // ), // ), // 'parent_type' => 'Accounts', // 'parent_doc_id' => '', // 'temp_id' => 'bd271276-1487-8083-bb80-5237f29820ab', // 'ecmlanguage' => 'pl_pl', // 'button' => 'test', // 'document_no' => '18/2013', // 'number' => '2013091718', // 'assigned_user_name' => 'Michał Zieliński', // 'assigned_user_id' => '1', // 'btn_assigned_user_name' => 'Wybierz', // 'btn_clr_assigned_user_name' => 'Wyczyść', // 'parent_name' => '"AGROPOL" CZĘŚCI ZAMIENNE WŁODZIMIERZ KAPUSTA', // 'parent_id' => '2248712', // 'btn_parent_name' => 'Wybierz', // 'btn_clr_parent_name' => 'Wyczyść', // 'type' => '0', // 'template_id' => 'ef0c4dea-ddf3-de51-9d08-512257d4b675', // 'template_name' => 'BSL Truck', // 'register_date' => '17.09.2013', // 'sell_date' => '17.09.2013', // 'stock_id' => '2962f1ad-79f4-a1ad-385e-4f286ad7acb5', // 'name' => '', // 'payment_date_d' => '', // 'prepaid' => '', // 'payment_date' => '17.09.2013', // 'prepaid_nr' => '', // 'payment_method' => '', // 'paid_val' => '', // 'payment_method_paid' => '', // 'parent_name_copy' => '"AGROPOL" CZĘŚCI ZAMIENNE WŁODZIMIERZ KAPUSTA', // 'to_nip' => '754-006-99-44', // 'parent_contact_name' => '', // 'currency_id' => 'PLN', // 'parent_contact_title' => '', // 'currency_value' => '', // 'parent_address_street' => 'WRZOSKI, UL. LEŚNA 2', // 'pdf_type' => 'K', // 'parent_address_postalcode' => '46-073', // 'parent_address_city' => 'CHRÓŚCINA', // 'parent_address_country' => '', // 'parent_shipping_address_name' => '', // 'parent_shipping_address_street' => '', // 'parent_shipping_address_postalcode' => '', // 'parent_shipping_address_city' => '', // 'parent_shipping_address_country' => '', // 'code_p' => '020099', // 'id_p' => '7a571024-02c2-7c7c-2429-501aa098386e', // 'category_id_p' => '', // 'currency_id_p' => 'undefined', // 'currency_symbol_p' => 'undefined', // 'ecmstockdocout_id' => '', // 'temp_item_id_p' => '', // 'temp_date_p' => '', // 'type_p' => '', // 'parent_doc_type' => '', // 'parent_doc_item_id' => '', // 'name_p' => 'IV53 TŁOK 82MM ACX83D', // 'quantity_p' => '1,00', // 'vat_name_p' => '23%', // 'vat_value_p' => '23.00', // 'vat_id_p' => '9ec174d1-db5e-8db6-9195-4e6e4a041e40', // 'unit_name_p' => 'undefined', // 'unit_id_p' => 'undefined', // 'stock_p' => '3,00', // 'subtotal' => '1,00', // 'total' => '1,23', // 'footer_module' => 'EcmReceipts', // 'footer_fields' => '$receipt_inside_inv_number', // 'footer_field' => '$receipt_inside_inv_number', // 'header_text' => ' // ', // 'header_module' => 'EcmReceipts', // 'header_fields' => '$receipt_inside_inv_number', // 'header_field' => '$receipt_inside_inv_number', // 'footer_text' => ' // ', // 'ads_module' => 'EcmReceipts', // 'ads_fields' => '$receipt_inside_inv_number', // 'ads_field' => '$receipt_inside_inv_number', // 'ads_text' => ' // ', // ); // ~ // Weird unformat number ? // $_POST['total'] = unformat_number(str_replace(array('.', ','), array('', '.'), $_POST['total'])); // $_POST['subtotal'] = unformat_number(str_replace(array('.', ','), array('', '.'), $_POST['subtotal'])); // dump($_POST); // exit; foreach ($focus->column_fields as $field) { //echo var_export($field, true) . PHP_EOL; //echo var_export($_POST[$field], true) . PHP_EOL; //continue; if (isset($_POST[$field])) { $value = $_POST[$field]; $focus->$field = $value; } } foreach ($focus->additional_column_fields as $field) { if (isset($_POST[$field])) { $value = $_POST[$field]; $focus->$field = $value; } } if (isset($_POST['to_is_vat_free']) && $_POST['to_is_vat_free']) { $focus->to_is_vat_free = 1; } else { $focus->to_is_vat_free = 0; } $pl = $_POST['position_list']; $focus->position_list = $pl; //$focus->wz_id=$_POST['out_id']; //$focus->paid_val = unformat_number($focus->paid_val); //$focus->prepaid = unformat_number($focus->prepaid); if ($focus->pdf_type == 'K') { $focus->ecmlanguage = 'pl_pl'; } else { $focus->ecmlanguage = 'en_us'; } if(strlen($parent_name = $_POST['parent_name_copy'])) { $focus->parent_name = $parent_name; } $focus->save($check_notify); if (isset($_POST['out_module']) && $_POST['out_module'] == "EcmQuotes" && isset($_POST['out_id']) && $_POST['out_id'] != '') { $query = "UPDATE ecmquotes SET status='s60' WHERE id='" . $_POST['out_id'] . "'"; $GLOBALS['db']->query($query); } if (isset($_POST['out_module']) && $_POST['out_module'] == "EcmStockDocOuts" && isset($_POST['out_id']) && $_POST['out_id'] != '') { $query = "UPDATE ecmreceipts SET wz_id='" . $_POST['out_id'] . "' WHERE id='" . $focus->id . "'"; $GLOBALS['db']->query($query); } $return_id = $focus->id; goto jump; //$r = $GLOBALS[db]->fetchByAssoc($GLOBALS[db]->query("select type,document_no from ecmreceipts where id='" . $return_id . "'")); //$file = "modules/EcmReceipts/xml/" . str_replace(" ", "", str_replace("/", "", $r['document_no'])) . ".xml"; // //fopen($file); // //if ($r['type'] == "correct") { // $xml = createCorrectInvoiceXml($return_id); //} else { // $xml = createInvoiceXml($return_id); //} // //file_put_contents($file, $xml); //chmod($file, 0777); $pt = @$_POST['parent_type']; $pdid = @$_POST['parent_doc_id']; // Close service. if ($pt == 'Service') { $usQuery = 'UPDATE `ecmservices` SET `status` = \'closed\' WHERE `id` = \'' . $pdid . '\';'; $GLOBALS['db']->query($usQuery); $drQuery = 'DELETE FROM `ecmreservations` WHERE `doc_id` = \'' . $pdid . '\';'; $GLOBALS['db']->query($drQuery); } jump: echo $return_id; die(); //header("Location: index.php?module=EcmReceipts&action=index"); //handleRedirect($return_id,'EcmReceipts');