822 lines
29 KiB
PHP
822 lines
29 KiB
PHP
<?php
|
|
|
|
if (!defined('sugarEntry') || !sugarEntry)
|
|
die('Not A Valid Entry Point');
|
|
|
|
//require_once('modules/EcmGroupSales/HeaderMenu.php');
|
|
|
|
global $sugar_version, $sugar_config, $current_user, $app_strings, $mod_strings, $current_user, $app_list_strings;
|
|
|
|
require_once('modules/EcmInvoiceOutOlds/EcmInvoiceOutOld.php');
|
|
|
|
require_once('modules/EcmInvoiceOutOlds/Forms.php');
|
|
|
|
require_once ('include/time.php');
|
|
|
|
require_once('include/json_config.php');
|
|
|
|
$json_config = new json_config();
|
|
|
|
|
|
$file = 'modules/EcmGroupSales/EcmGroupSale.php';
|
|
if (file_exists($file)) {
|
|
$cc = array();
|
|
require_once($file);
|
|
$cc = EcmGroupSale::loadSettings();
|
|
}
|
|
|
|
$OPT = array();
|
|
|
|
$OPT['row_item_height'] = $cc['row_item_height'];
|
|
$OPT['row_item_height_selected'] = $cc['row_item_height_selected'];
|
|
$OPT['rows_on_item_list'] = $cc['rows_on_item_list'];
|
|
$OPT['position_table_height'] = $OPT['row_item_height'] * $OPT['rows_on_item_list'] + 40 + $OPT['rows_on_item_list'] * 4;
|
|
$OPT['quick_product_item_adding'] = $cc['quick_product_item_adding'];
|
|
|
|
if ($cc['checkbox_demo'] == 1) {
|
|
$query = "SELECT COUNT(id) as count FROM ecminvoiceoutolds WHERE deleted='0'";
|
|
$result = $GLOBALS['db']->query($query);
|
|
if (is_resource($result)) {
|
|
$row = $GLOBALS['db']->fetchByAssoc($result);
|
|
if (isset($row['count']) && is_numeric($row['count'] = intval($row['count'])) && $row['count'] >= 10)
|
|
$OPT['checkbox_demo'] = 1;
|
|
}
|
|
}
|
|
|
|
$OPT['check_parent_id'] = true;
|
|
|
|
$cq = $current_user->getPreference('confirm_invoiceouts');
|
|
$OPT['user']['confirm_invoiceouts'] = ((isset($cq) && $cq) ? 1 : 0);
|
|
|
|
|
|
|
|
$focus = new EcmInvoiceOutOld();
|
|
|
|
if (!$focus->id)
|
|
$temp_id = create_guid();
|
|
else
|
|
$temp_id = $focus->id;
|
|
|
|
|
|
|
|
|
|
//for outside modules
|
|
if (isset($_REQUEST['out_module']) && $_REQUEST['out_module'] != '' && isset($_REQUEST['out_id']) && $_REQUEST['out_id'] != '') {
|
|
// $focus->wz_id = $_REQUEST['out_id'];
|
|
$outModule = $_REQUEST['out_module'];
|
|
$outId = $_REQUEST['out_id'];
|
|
$OPT['fromOutside'] = true;
|
|
$path = 'modules/' . $outModule . '/LoadEcmInvoiceOutOlds.php';
|
|
if (file_exists($path)) {
|
|
require_once($path);
|
|
$_REQUEST['record'] = '';
|
|
|
|
$outside_create = true;
|
|
}
|
|
}
|
|
|
|
|
|
$pt = $pdid = null;
|
|
|
|
if (isset($_REQUEST['record']) && $_REQUEST['record'] != '') {
|
|
|
|
$focus->retrieve($_REQUEST['record']);
|
|
|
|
if (isset($focus->id) && $focus->id != '') {
|
|
if ($focus->accepted == 1) {
|
|
echo 'You cannot edit this invoiceout. This invoiceout is accepted. <a href="index.php?module=' . $_REQUEST['return_module'] . '&action=' . $_REQUEST['return_action'] . '&record=' . $_REQUEST['return_id'] . '">return</a>';
|
|
return;
|
|
}
|
|
$focus->format_all_fields();
|
|
$focus->position_list = str_replace('"', '\"', $focus->getPositionList());
|
|
|
|
//has wz?
|
|
$r = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("SELECT ecmstockdocout_id as wz FROM ecminvoiceoutolditems WHERE ecminvoiceoutold_id='" . $focus->id . "'"));
|
|
|
|
if ($r['wz'] && $r['wz'] != '')
|
|
$OPT['from_wz'] = true;
|
|
}
|
|
} elseif ($_REQUEST['parent_doc_type'] == 'EcmStockDocOuts') {
|
|
//unset($_SESSION['temp_id']);
|
|
//add mz 2012-04-11
|
|
$OPT['new_number'] = true;
|
|
$OPT['from_wz'] = true;
|
|
|
|
|
|
//create products array
|
|
$r = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("SELECT * FROM ecmstockdocouts WHERE id='" . $_REQUEST['parent_doc_id'] . "'"));
|
|
|
|
$a = new Account();
|
|
$a->retrieve($r['parent_id']);
|
|
|
|
$focus->parent_id = $r['parent_id'];
|
|
$focus->parent_name = $r['parent_name'];
|
|
$focus->parent_address_street = $r['parent_address_street'];
|
|
$focus->parent_address_city = $r['parent_address_city'];
|
|
$focus->parent_address_postalcode = $r['parent_address_postalcode'];
|
|
$focus->parent_address_country = $r['parent_address_country'];
|
|
$focus->to_nip = $a->to_vatid;
|
|
$focus->ecmpaymentcondition_id = $a->ecmpaymentcondition_id;
|
|
$focus->supplier_code = $a->supplier_code;
|
|
|
|
//saturn??
|
|
if ($a->parent_id=='1249') {
|
|
$s = new Account();
|
|
$s->retrieve('1249');
|
|
$a->ecmpaymentcondition_id = $s->ecmpaymentcondition_id;
|
|
unset($s);
|
|
}
|
|
|
|
|
|
$pc = new EcmPaymentCondition();
|
|
$pc->retrieve($a->ecmpaymentcondition_id);
|
|
$focus->ecmpaymentcondition_id = $pc->id;
|
|
$focus->ecmpaymentcondition_name = $pc->name;
|
|
if ($a->parent_id!='1249')
|
|
$focus->payment_date=$GLOBALS['timedate']->to_display_date(date("Y-m-d",mktime()+3600*24*$pc->days));
|
|
else {
|
|
$s = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("SELECT delivery_date FROM ecmsales WHERE id='".$r['ecmsale_id']."'"));
|
|
$d = date('Y-m-t', strtotime($s['delivery_date']));
|
|
$focus->payment_date=$GLOBALS['timedate']->to_display_date(date("Y-m-d",mktime()+3600*24*60));
|
|
}
|
|
|
|
$s = new EcmSale();
|
|
$s->retrieve($r['ecmsale_id']);
|
|
|
|
//delivery address
|
|
$focus->parent_shipping_address_name = $s->shipping_address_name;
|
|
$focus->parent_shipping_address_street = $s->shipping_address_street;
|
|
$focus->parent_shipping_address_city = $s->shipping_address_city;
|
|
$focus->parent_shipping_address_postalcode = $s->shipping_address_postalcode;
|
|
$focus->parent_shipping_address_country = $s->shipping_address_country;
|
|
|
|
$focus->parent_contact_name = $r['parent_contact_name'];
|
|
$focus->parent_contact_title = $r['parent_contact_title'];
|
|
$focus->order_no = $r['parent_order_no'];
|
|
$focus->contact_id = $r['contact_id'];
|
|
$focus->name = $r['name'];
|
|
|
|
$focus->wz_id = $_REQUEST['parent_doc_id'];
|
|
|
|
|
|
//set possition list
|
|
$pl = array ();
|
|
|
|
$res = $GLOBALS ['db']->query ( "SELECT * FROM ecmstockdocoutitems WHERE ecmstockdocout_id ='" . $_REQUEST ['parent_doc_id'] . "' order by position" );
|
|
|
|
global $app_list_strings;
|
|
|
|
while ( $r = $GLOBALS ['db']->fetchByAssoc ( $res ) ) {
|
|
|
|
$t = $GLOBALS ['db']->fetchByAssoc ( $GLOBALS ['db']->query ( "SELECT unit_id,vat_value,vat_id,vat_name FROM ecmproducts WHERE id='" . $r['ecmproduct_id'] . "'" ) );
|
|
|
|
$subprice = $r['price_sell'];
|
|
$subtotal = $r['quantity'] * $subprice;
|
|
|
|
$vat = $subtotal * ($t['vat_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 ['price_sell'];
|
|
$position['subprice'] = $subprice;
|
|
$position['price'] = $price;
|
|
$position['subtotal'] = $subtotal;
|
|
$position['total'] = $total;
|
|
|
|
// $position['selling_price'] = $r['price'];
|
|
$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'] = $t ['vat_id'];
|
|
$position ['vat_name'] = $t ['vat_name'];
|
|
$position ['vat_value'] = $t ['vat_value'];
|
|
$position ['category_id'] = $r ['ecmproductcategory_id'];
|
|
$position ['currency_id'] = $r ['currency_id'];
|
|
$position ['currency_name'] = $r ['currency_name'];
|
|
$position ['recipient_code'] = $r ['supplier_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" );
|
|
|
|
|
|
//include_once ("modules/EcmStockOperations/EcmStockOperation.php");
|
|
//$op = new EcmStockOperation ();
|
|
//$position ['stock'] = $op->getStock ( $r ['ecmproduct_id'], $focus->stock_id );
|
|
//$position ['parent_doc_rq'] = $op->getStockR ( $r ['ecmproduct_id'], $focus->stock_id );
|
|
|
|
|
|
$pl [] = $position;
|
|
}
|
|
|
|
|
|
$focus->position_list = str_replace ( '"', '\"', $json->encode ( $pl ) );
|
|
} elseif ($_REQUEST['parent_doc_type'] == 'EcmQuotes') {
|
|
|
|
|
|
session_start();
|
|
$positions = $_SESSION[$_REQUEST['temp_id']];
|
|
//var_dump($_SESSION[$_REQUEST['temp_id']]);
|
|
$sales = array();
|
|
foreach ($positions as $v)
|
|
$sales[] = $v['parent_doc_id'];
|
|
|
|
$OPT['new_number'] = true;
|
|
$OPT['parent_doc_type'] = 'EcmQoutes';
|
|
|
|
$temp_id = $_REQUEST['temp_id'];
|
|
|
|
//set accounts information
|
|
$r = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("SELECT * FROM ecmquotes WHERE id='" . $positions[0]['parent_doc_id'] . "'"));
|
|
|
|
$focus->payment_method = $r['payment_method'];
|
|
//$focus->payment_date_d = $r['payment_deadline'];
|
|
$focus->parent_id = $r['parent_id'];
|
|
$focus->parent_name = $r['parent_name'];
|
|
$focus->parent_contact_name = $r['parent_contact_name'];
|
|
$focus->parent_contact_title = $r['parent_contact_title'];
|
|
$focus->parent_address_street = $r['parent_address_street'];
|
|
$focus->parent_address_city = $r['parent_address_city'];
|
|
$focus->parent_address_postalcode = $r['parent_address_postalcode'];
|
|
$focus->parent_address_country = $r['parent_address_country'];
|
|
$focus->order_no = $r['order_no'];
|
|
$focus->to_is_vat_free = $r['to_is_vat_free'];
|
|
$focus->contact_id = $r['contact_id'];
|
|
$focus->stock_id = $r['stock_id'];
|
|
$focus->to_nip = $r['to_vatid'];
|
|
$focus->currency_value = $r['currency_value'];
|
|
$focus->pdf_type = $r['invoice_type'];
|
|
$focus->currency_id = $r['currency_id'];
|
|
$focus->parent_shipping_address_name = $r['parent_shipping_address_name'];
|
|
$focus->parent_shipping_address_street = $r['parent_shipping_address_street'];
|
|
$focus->parent_shipping_address_city = $r['parent_shipping_address_city'];
|
|
$focus->parent_shipping_address_postalcode = $r['parent_shipping_address_postalcode'];
|
|
$focus->parent_shipping_address_country = $r['parent_shipping_address_country'];
|
|
//set possition list
|
|
|
|
//get prepayment informations
|
|
global $db;
|
|
$res = $db->query("SELECT document_no, inv_value, currency_id, currency_value FROM ecmprepaymentinvoices WHERE ecmquote_id IN ('".implode("','", $sales)."')");
|
|
$sum = 0;
|
|
while ($row = $db->fetchByAssoc($res)) {
|
|
$sum+=$row['inv_value'];
|
|
$focus->prepaid_nr.=$row['document_no'].' ';
|
|
//$focus->currency_id = $row['currency_id'];
|
|
//$focus->currency_value = $row['currency_value'];
|
|
}
|
|
|
|
//get older invoices prepaid
|
|
$old = $db->fetchByAssoc($db->query("SELECT sum(i.prepaid) as s FROM ecminvoiceoutolds AS i INNER JOIN ecminvoiceoutolditems as ii ON i.id=ii.ecminvoiceoutold_id WHERE ii.parent_doc_id IN ('".implode("','", $sales)."')"));
|
|
|
|
// echo '<pre>'. var_export($sum, true);
|
|
// exit;
|
|
|
|
$sum+=$old['s'];
|
|
|
|
$focus->prepaid=$sum;
|
|
|
|
// echo '<pre>'. var_export($sum, true);
|
|
// exit;
|
|
|
|
//get parent currency
|
|
$cur = $db->fetchByAssoc($db->query("SELECT currency_id as cid FROM accounts WHERE id='".$focus->parent_id."'"));
|
|
|
|
$c = new Currency();
|
|
$c->retrieve($cur['cid']);
|
|
|
|
$focus->currency_id = $cur['cid'];
|
|
$focus->currency_value = $c->conversion_rate;
|
|
unset($c);
|
|
|
|
$pl = array();
|
|
|
|
foreach ($positions as $pos) {
|
|
|
|
$r = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("SELECT * FROM ecmquoteitems WHERE id ='" . $pos['parent_doc_item_id'] . "'"));
|
|
$t = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("SELECT type FROM ecmproducts WHERE id='".$pos['id']."'"));
|
|
$position = array();
|
|
|
|
// echo '<pre>' . var_export($r, true) . '</pre>';
|
|
// echo '<pre>' . var_export($t, true) . '</pre>';
|
|
// exit;
|
|
|
|
$position['iid'] = create_guid();
|
|
$position['code'] = $pos['code'];
|
|
$position['name'] = $pos['name'];
|
|
$position['id'] = $pos['id'];
|
|
$position['quantity'] = $pos['quantity'];
|
|
//calculate currency
|
|
$position['startprice'] = $r['price'];
|
|
/*
|
|
if ($r['currency_id']==$focus->currency_id)
|
|
$position['startprice'] = $r['price'];
|
|
else {
|
|
$c = new Currency();
|
|
$c->retrieve($r['currency_id']);
|
|
if ($focus->currency_id=='PLN') {
|
|
$position['startprice'] = $r['price']*$c->conversion_rate;
|
|
} else {
|
|
$position['startprice'] = $r['price']/$focus->currency_value;
|
|
}
|
|
}
|
|
*/
|
|
//$position['selling_price'] = $r['price'];
|
|
$position['discount'] = $r['discount'];
|
|
$position['total'] = $r['total'];
|
|
$position['unit_id'] = $r['dd_unit_id'];
|
|
$position['unit_name'] = $r['dd_unit_name'];
|
|
$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['ecmquote_id'];
|
|
$position['parent_doc_type'] = 'EcmQuotes';
|
|
$position['parent_doc_item_id'] = $pos['parent_doc_item_id'];
|
|
$position['temp_item_id'] = create_guid();
|
|
$position['temp_date'] = date("Y-m-d H:i:s");
|
|
|
|
include_once("modules/EcmStockOperations/EcmStockOperation.php");
|
|
$op = new EcmStockOperation();
|
|
$position['stock'] = $op->getStock($r['ecmproduct_id'], $focus->stock_id);
|
|
$position['parent_doc_rq'] = $op->getStockR($r['ecmproduct_id'], $focus->stock_id);
|
|
|
|
$pl[] = $position;
|
|
}
|
|
|
|
$focus->position_list = str_replace('"', '\"', $json->encode($pl));
|
|
}
|
|
elseif ('EcmServices' == @$_REQUEST['parent_doc_type']) {
|
|
/* BOF: EcmServices. */
|
|
$pt = 'Service';
|
|
$pdid = $id = @$_REQUEST['uid'];
|
|
|
|
$OPT['new_number'] = true;
|
|
$OPT['from_sale'] = true;
|
|
|
|
$temp_id = $_REQUEST['temp_id'];
|
|
|
|
//set accounts information
|
|
$query = 'SELECT s.* FROM `ecmservices` AS s WHERE s.`id` = \'' . $id . '\';';
|
|
|
|
$result = $GLOBALS['db']->query($query);
|
|
$r = $GLOBALS['db']->fetchByAssoc($result);
|
|
|
|
//echo '<pre>' . var_export($_REQUEST, true) . PHP_EOL;
|
|
//echo '<pre>' . var_export($r, true) . PHP_EOL;
|
|
//echo '<pre>' . var_export($mod_strings, true) . PHP_EOL;
|
|
//exit;
|
|
|
|
$focus->parent_id = $r['parent_id'];
|
|
$focus->parent_name = $r['parent_name'];
|
|
$focus->parent_contact_name = $r['parent_contact_name'];
|
|
$focus->parent_contact_title = $r['parent_contact_title'];
|
|
$focus->parent_address_street = $r['parent_address_street'];
|
|
$focus->parent_address_city = $r['parent_address_city'];
|
|
$focus->parent_address_postalcode = $r['parent_address_postalcode'];
|
|
$focus->parent_address_country = $r['parent_address_country'];
|
|
$focus->order_no = $r['order_no'];
|
|
$focus->to_is_vat_free = $r['to_is_vat_free'];
|
|
$focus->contact_id = $r['contact_id'];
|
|
$focus->stock_id = $r['stock_id'];
|
|
$focus->name = sprintf(@$mod_strings['SERVICE_INVOICE_NAME'], $r['document_no']);
|
|
|
|
//get NIP
|
|
//$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("SELECT nip FROM accounts WHERE id='" . $focus->parent_id . "'"));
|
|
|
|
$focus->to_vatid = $r['nip'];
|
|
|
|
//set possition list
|
|
$pl = array();
|
|
|
|
$pQuery = 'SELECT si.* FROM `ecmserviceitems` AS si WHERE si.`ecmservice_id` = \'' . $id . '\' AND si.`product_type` != \'income\';';
|
|
|
|
$pResult = $GLOBALS['db']->query($pQuery);
|
|
while ($ir = $GLOBALS['db']->fetchByAssoc($pResult)) {
|
|
$position = array();
|
|
|
|
$position['iid'] = create_guid();
|
|
$position['code'] = $ir['code'];
|
|
$position['name'] = $ir['name'];
|
|
$position['id'] = $ir['ecmproduct_id'];
|
|
$position['quantity'] = $ir['quantity'];
|
|
$position['price'] = $ir['price'];
|
|
$position['selling_price'] = $ir['price'];
|
|
$position['discount'] = $ir['discount'];
|
|
$position['total'] = $ir['total'];
|
|
$position['unit_id'] = $ir['dd_unit_id'];
|
|
$position['unit_name'] = $ir['dd_unit_name'];
|
|
$position['vat_id'] = $ir['ecmvat_id'];
|
|
$position['vat_name'] = $ir['ecmvat_name'];
|
|
$position['vat_value'] = $ir['ecmvat_value'];
|
|
$position['category_id'] = $ir['ecmproductcategory_id'];
|
|
$position['currency_id'] = $ir['currency_id'];
|
|
$position['currency_name'] = $ir['currency_name'];
|
|
$position['recipient_code'] = $ir['recipient_code'];
|
|
$position['ecmstockdocout_id'] = $ir['ecmstockdocout_id'];
|
|
$position['type'] = $ir['product_type'];
|
|
$position['temp_item_id'] = $ir['temp_item_id'];
|
|
$position['temp_date'] = date("Y-m-d H:i:s");
|
|
//
|
|
$position['parent_doc_id'] = $id;
|
|
$position['parent_doc_type'] = 'EcmService';
|
|
|
|
include_once("modules/EcmStockOperations/EcmStockOperation.php");
|
|
$op = new EcmStockOperation();
|
|
|
|
$position['stock'] = $op->getStock($ir['ecmproduct_id'], $focus->stock_id);
|
|
|
|
$pl[] = $position;
|
|
}
|
|
|
|
//exit;
|
|
|
|
$focus->position_list = str_replace('"', '\"', $json->encode($pl));
|
|
|
|
/* EOF: EcmServices. */
|
|
} elseif (isset($_REQUEST['ecmsale_id'])) {
|
|
|
|
$OPT['new_number'] = true;
|
|
$OPT['from_sale'] = true;
|
|
|
|
$s = new EcmSale();
|
|
$s->retrieve($_REQUEST['ecmsale_id']);
|
|
|
|
$a = new Account();
|
|
$a->retrieve($s->parent_id);
|
|
|
|
$focus->parent_id = $s->parent_id;
|
|
$focus->parent_name = $s->parent_name;
|
|
$focus->parent_address_street = $s->parent_address_street;
|
|
$focus->parent_address_city = $s->parent_address_city;
|
|
$focus->parent_address_postalcode = $s->parent_address_postalcode;
|
|
$focus->parent_address_country = $s->parent_address_country;
|
|
$focus->to_nip = $s->to_vatid;
|
|
$focus->ecmpaymentcondition_id = $s->ecmpaymentcondition_id;
|
|
$focus->supplier_code = $a->supplier_code;
|
|
$pc = new EcmPaymentCondition();
|
|
$pc->retrieve($s->ecmpaymentcondition_id);
|
|
$focus->ecmpaymentcondition_name = $pc->name;
|
|
//$focus->payment_date=$GLOBALS['timedate']->to_display_date(date("Y-m-d",mktime()+3600*24*$pc->days));
|
|
|
|
//delivery address
|
|
$focus->parent_shipping_address_name = $s->parent_shipping_address_name;
|
|
$focus->parent_shipping_address_street = $s->parent_shipping_address_street;
|
|
$focus->parent_shipping_address_city = $s->parent_shipping_address_city;
|
|
$focus->parent_shipping_address_postalcode = $s->parent_shipping_address_postalcode;
|
|
$focus->parent_shipping_address_country = $s->parent_shipping_address_country;
|
|
|
|
$focus->template_id = $s->template_id;
|
|
$focus->template_name = $s->template_name;
|
|
$focus->parent_contact_name = $s->parent_contact_name;
|
|
$focus->parent_contact_title = $s->parent_contact_title;
|
|
$focus->order_no = $s->parent_order_no;
|
|
$focus->contact_id = $s->contact_id;
|
|
$focus->name = $s->name;
|
|
|
|
$focus->register_date=$GLOBALS['timedate']->to_display_date(date("Y-m-d"));
|
|
$focus->sell_date=$GLOBALS['timedate']->to_display_date(date("Y-m-d"));
|
|
$focus->status="accepted";
|
|
$focus->type = "normal";
|
|
$focus->assigned_user_id=$s->assigned_user_id;
|
|
$focus->created_by=$s->created_by;
|
|
$focus->modified_user_id=$s->modified_user_id;
|
|
$focus->pdf_type=$s->pdf_type;
|
|
$focus->currency_id=$s->currency_id;
|
|
|
|
unset($s);
|
|
|
|
|
|
//set possition list
|
|
$pl = array ();
|
|
|
|
$res = $GLOBALS ['db']->query ( "SELECT * FROM ecmsaleitems WHERE ecmsale_id ='" . $_REQUEST['ecmsale_id'] . "' order by position" );
|
|
|
|
global $app_list_strings;
|
|
|
|
while ( $r = $GLOBALS ['db']->fetchByAssoc ( $res ) ) {
|
|
|
|
$t = $GLOBALS ['db']->fetchByAssoc ( $GLOBALS ['db']->query ( "SELECT id, unit_id FROM ecmproducts WHERE deleted='0' AND code='" . $r['code'] . "'" ) );
|
|
|
|
echo $r['code'].' - '.$t['id'].'<br>';
|
|
|
|
$subprice = $r['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'] = $t ['id'];
|
|
$position ['quantity'] = $r ['quantity'];
|
|
// calculate currency
|
|
$position ['startprice'] = $r ['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 ['ecmsale_id'];
|
|
$position ['parent_doc_type'] = 'EcmSale';
|
|
$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;
|
|
}
|
|
|
|
// var_dump($pl);
|
|
|
|
$focus->position_list = str_replace('"', '\"', $json->encode($pl));
|
|
|
|
}
|
|
else {
|
|
if (isset($_REQUEST['contact_id']) && $_REQUEST['contact_id'] != '' && isset($_REQUEST['contact_name']) && $_REQUEST['contact_name'] != '') {
|
|
$_REQUEST['parent_type'] = 'Contacts';
|
|
$_REQUEST['parent_name'] = $_REQUEST['contact_name'];
|
|
$_REQUEST['parent_id'] = $_REQUEST['contact_id'];
|
|
$OPT['check_parent_id'] = false;
|
|
}
|
|
|
|
if (isset($_REQUEST['account_id']) && $_REQUEST['account_id'] != '' && isset($_REQUEST['account_name']) && $_REQUEST['account_name'] != '') {
|
|
$_REQUEST['parent_type'] = 'Accounts';
|
|
$_REQUEST['parent_name'] = $_REQUEST['account_name'];
|
|
$_REQUEST['parent_id'] = $_REQUEST['account_id'];
|
|
$OPT['check_parent_id'] = false;
|
|
}
|
|
|
|
$OPT['new_number'] = true;
|
|
|
|
if (isset($cc)) {
|
|
|
|
//payment condition
|
|
$cc_list = EcmGroupSale::getPositionList('ecmpaymentconditions');
|
|
//$focus->ecmpaymentcondition_id = $cc['default_payment_condition'];
|
|
//$focus->ecmpaymentcondition_name = $cc_list[$cc['default_payment_condition']];
|
|
//default template
|
|
$focus->template_id = $cc['default_document_template'];
|
|
$fftemplateid = $focus->template_id;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$OPT['old_status'] = (isset($focus->status) && $focus->status != '') ? $focus->status : 'not_accepted';
|
|
$OPT['invoice']['type'] = (isset($focus->type) && $focus->type != '') ? $focus->status : 'normal';
|
|
|
|
|
|
if ($_REQUEST['isDuplicate'] == 'true' || $outside_create == true) {
|
|
$_POST['isDuplicate'] = true;
|
|
$focus->id = '';
|
|
$OPT['isDuplicate'] = true;
|
|
$OPT['new_number'] = true;
|
|
}
|
|
|
|
if (!isset($focus->discount) || $focus->discount == '')
|
|
$focus->discount = '0.00';
|
|
|
|
if ($OPT['new_number'] == true) {
|
|
|
|
$datef = $current_user->getPreference('datef');
|
|
|
|
if ($datef != '')
|
|
$sugar_config['datef'];
|
|
|
|
$focus->register_date = date($datef);
|
|
|
|
//$focus->payment_date = date($datef, mktime() + 30 * 24 * 60 * 60);
|
|
|
|
$focus->sell_date = date($datef);
|
|
}
|
|
|
|
|
|
$cur = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select value from currency_nbp_archive where date<'".$focus->register_date."' and currency_id='".$focus->currency_id."' order by date desc limit 0,1;"));
|
|
|
|
if ($cur['value'])
|
|
$focus->currency_value_nbp = $cur['value'];
|
|
|
|
//echo "select value from currency_nbp_archive where date<'".$focus->register_date."' and currency_id='".$focus->currency_id."' order by date desc limit 0,1;";
|
|
|
|
if (isset($_REQUEST['out_module']) && $_REQUEST['out_module'] != '' && isset($_REQUEST['out_id']) && $_REQUEST['out_id'] != '') {
|
|
//todo dodać relację
|
|
//$focus->wz_id = $_REQUEST['out_id'];
|
|
}
|
|
|
|
$tmp = $current_user->getPreference('num_grp_sep');
|
|
if (!isset($tmp) || $tmp == '' || $tmp == NULL)
|
|
$tmp = $sugar_config['default_number_grouping_seperator'];
|
|
$OPT['sep_1000'] = $tmp;
|
|
|
|
$tmp = $current_user->getPreference('dec_sep');
|
|
if (!isset($tmp) || $tmp == '' || $tmp == NULL)
|
|
$tmp = $sugar_config['default_decimal_seperator'];
|
|
$OPT['dec_sep'] = $tmp;
|
|
|
|
$tmp = $current_user->getPreference('default_currency_significant_digits');
|
|
if (!isset($tmp) || $tmp == '' || $tmp == NULL)
|
|
$tmp = $sugar_config['default_currency_significant_digits'];
|
|
$OPT['dec_len'] = $tmp;
|
|
|
|
|
|
|
|
$OPT['default_unit'] = "1";
|
|
|
|
$OPT['default_vat'] = "23.00";
|
|
|
|
$OPT['default_category'] = "";
|
|
|
|
$OPT['default_currency'] = "-99";
|
|
|
|
$OPT['type'] = $focus->type;
|
|
|
|
$OPT['to_is_vat_free'] = $focus->to_is_vat_free;
|
|
|
|
|
|
require_once('modules/EcmTexts/EcmText.php');
|
|
foreach ($app_list_strings['ecmlanguages_dom'] as $key => $value) {
|
|
$data = EcmText::LoadText(null, null, "EcmInvoiceOutOlds", $key);
|
|
//var_dump($data);
|
|
if (isset($data[0]) && isset($data[0]['data']))
|
|
$d = $data[0]['data']; else {
|
|
$d = $PDFLL;
|
|
if (!isset($d['labels']))
|
|
$d['labels'] = $PDFLL['labels'];
|
|
if (!isset($d['texts']['Contacts']['header_text']))
|
|
$d['texts']['Contacts']['header_text'] = $mod_strings['LBL_DEFAULT_CONTACT_HEADER_TEXT'];
|
|
if (!isset($d['texts']['Contacts']['footer_text']))
|
|
$d['texts']['Contacts']['footer_text'] = $mod_strings['LBL_DEFAULT_CONTACT_FOOTER_TEXT'];
|
|
if (!isset($d['texts']['Contacts']['ads_text']))
|
|
$d['texts']['Contacts']['ads_text'] = $mod_strings['LBL_DEFAULT_CONTACT_ADS_TEXT'];
|
|
if (!isset($d['texts']['Accounts']['header_text']))
|
|
$d['texts']['Accounts']['header_text'] = $mod_strings['LBL_DEFAULT_ACCOUNT_HEADER_TEXT'];
|
|
if (!isset($d['texts']['Accounts']['footer_text']))
|
|
$d['texts']['Accounts']['footer_text'] = $mod_strings['LBL_DEFAULT_ACCOUNT_FOOTER_TEXT'];
|
|
if (!isset($d['texts']['Accounts']['ads_text']))
|
|
$d['texts']['Accounts']['ads_text'] = $mod_strings['LBL_DEFAULT_ACCOUNT_ADS_TEXT'];
|
|
}
|
|
$OPT['ecmlanguage'][$key]['texts'] = $d['texts'];
|
|
}
|
|
|
|
$w = $GLOBALS[db]->query("select name,id,value from ecmvats where deleted='0' order by name");
|
|
$nvats = mysql_num_rows($w);
|
|
while ($r = $GLOBALS[db]->fetchByAssoc($w)) {
|
|
$VAT[$r['id']] = array(
|
|
"id" => $r['id'],
|
|
"name" => $r['name'],
|
|
"value" => $r['value']
|
|
);
|
|
}
|
|
|
|
|
|
|
|
$show_pdf = $current_user->getPreference('show_pdf_in_div');
|
|
if (!isset($show_pdf)) {
|
|
require_once('modules/EcmGroupSales/EcmGroupSale.php');
|
|
$cc = EcmGroupSale::loadSettings();
|
|
$show_pdf = $cc['show_pdf_in_div_global'];
|
|
}
|
|
|
|
$json = getJSONobj();
|
|
|
|
$larr = array("en_us", "pl_pl", "ge_ge");
|
|
foreach ($larr as $la) {
|
|
$lv = return_app_list_strings_language($la);
|
|
$UNIT_LANG[$la] = $lv['ecmproducts_unit_dom'];
|
|
}
|
|
$scriptOpt.='<script language="javascript">
|
|
var UNIT_LANG=' . str_replace('"', '\"', $json->encode($UNIT_LANG)) . ';
|
|
</script>';
|
|
|
|
|
|
|
|
|
|
|
|
require_once('include/MVC/View/SugarView.php');
|
|
|
|
require_once('modules/EcmInvoiceOutOlds/view/EditView/view.edit.my.php');
|
|
|
|
$edit = new ViewEditMy();
|
|
$edit->ss = new Sugar_Smarty();
|
|
$edit->module = 'EcmInvoiceOutOlds';
|
|
|
|
$edit->bean = $focus;
|
|
|
|
|
|
$edit->tplFile = 'include/ECM/EcmViews/EditView/Tabs/EditView.tpl';
|
|
$stocks = '<option value="">' . $GLOBALS['app_list_strings']['stock_select'] . '</option>';
|
|
$w = $GLOBALS['db']->query("select name,id from ecmstocks where deleted='0' order by name asc");
|
|
while ($r = $GLOBALS['db']->fetchByAssoc($w)) {
|
|
$stocks.='<option value="' . $r['id'] . '"';
|
|
if ($r['id'] == $focus->stock_id)
|
|
$stocks.=' selected';
|
|
if ((!$focus->stock_id || $focus->stock_id=='') && $r['id']=='2962f1ad-79f4-a1ad-385e-4f286ad7acb5')
|
|
$stocks.=' selected';
|
|
$stocks.='>' . $r['name'] . '</option>';
|
|
|
|
}
|
|
|
|
if (isset($_REQUEST['isCorrect']) && $_REQUEST['isCorrect'] == 'true') {
|
|
$OPT['new_number'] = true;
|
|
}
|
|
|
|
$edit->ss->assign("PARENT_TYPE", $pt ? : 'Accounts');
|
|
$edit->ss->assign("PARENT_DOC_ID", $pdid);
|
|
|
|
$edit->ss->assign("STOCK", $stocks);
|
|
|
|
$edit->ss->assign("OPT", $OPT);
|
|
|
|
$edit->ss->assign("TEMP_ID", $temp_id);
|
|
|
|
$scriptOpt = '<script language="javascript">
|
|
|
|
var SHOW_PDF_IN_DIV =' . $show_pdf . ';
|
|
|
|
var UNIT =' . str_replace('"', '\"', $json->encode($GLOBALS['app_list_strings']['ecmproducts_unit_dom'])) . ';
|
|
|
|
var VAT = ' . str_replace('"', '\"', $json->encode($VAT)) . ';
|
|
|
|
var OPT = ' . str_replace('"', '\"', $json->encode($OPT)) . ';
|
|
|
|
var MOD = ' . str_replace('"', '\"', $json->encode($mod_strings)) . ';
|
|
|
|
var N;
|
|
|
|
</script>';
|
|
|
|
echo $scriptOpt;
|
|
|
|
$edit->preDisplay();
|
|
|
|
if (isset($_REQUEST['isCorrect']) && $_REQUEST['isCorrect'] == 'true') {
|
|
$focus->type = 'correct';
|
|
$focus->name = '';
|
|
$focus->ecminvoiceoutold_id = $focus->id;
|
|
$focus->ecminvoiceoutold_name = $focus->document_no;
|
|
$focus->id = '';
|
|
|
|
$datef = $current_user->getPreference('datef');
|
|
if ($datef != '')
|
|
$sugar_config['datef'];
|
|
$focus->register_date = date($datef);
|
|
$focus->sell_date = date($datef);
|
|
}
|
|
|
|
|
|
if (isset($fftemplateid) && $fftemplateid != '')
|
|
$focus->template_id = $fftemplateid;
|
|
|
|
$arr_template = $focus->getTemplateList();
|
|
|
|
if (isset($outside_create) && $outside_create == true) {
|
|
$edit->ss->assign("OUT_MODULE", $_REQUEST['out_module']);
|
|
$edit->ss->assign("OUT_ID", $_REQUEST['out_id']);
|
|
}
|
|
|
|
$arr_template = $focus->getTemplateList();
|
|
$tt="";
|
|
foreach($arr_template as $k=>$v){
|
|
$tt.='<option value="'.$k.'"';
|
|
if($k==$focus->template_id)$tt.=' selected';
|
|
$tt.='>'.$v.'</option>';
|
|
}
|
|
|
|
$edit->ss->assign("DOCUMENT_TEMPLATES_OPTIONS", $tt);
|
|
$edit->ss->assign("POSITION_LIST", $focus->position_list);
|
|
$edit->ss->assign("MFP", $focus->loadParserArray());
|
|
|
|
if (isset($focus->id) && $focus->id!='' && $current_user->id!='1')
|
|
die ('NIE WOLNO SAMEMU EDYTOWAĆ FAKTUR!');
|
|
|
|
echo $edit->display(); |