diff --git a/REST/functions.php b/REST/functions.php
index e590d8e5..51ea0ba3 100644
--- a/REST/functions.php
+++ b/REST/functions.php
@@ -56,26 +56,38 @@
$gotAllProducts = false;
continue;
} else {
- $fvPrice = $db->fetchByAssoc($db->query("
- SELECT i.id, i.document_no, ii.price_start, ii.ecmvat_value, ii.ecmvat_name, ii.ecmvat_id
- FROM ecminvoiceoutitems AS ii
- INNER JOIN ecminvoiceouts AS i
- ON i.id = ii.ecminvoiceout_id
- WHERE
- i.parent_id= '1b9643ca-5b1a-8f9b-b809-586b5619b068' AND
- i.currency_id = 'PLN' AND
- ii.ecmproduct_id = '$p->id'
- ORDER BY i.register_date DESC
- LIMIT 0,1
- "));
-
- if (!isset($fvPrice)) {
- $price_start = 0;
- echo " Brak ceny
";
+ // pricebook price?
+ $pricebookPrice = $db->fetchByAssoc($db->query("
+ SELECT price FROM ecmpricebooks_ecmproducts
+ WHERE ecmpricebook_id = '3e78ac33-7c46-1b94-0a67-653a17c06f9e'
+ AND ecmproduct_id='$p->id'
+ AND deleted=0 LIMIT 0,1"));
+ if (isset($pricebookPrice)) {
+ $price_start = $pricebookPrice['price'];
+ echo " Cena: ".$price_start." (Amazon_2023)
";
} else {
- $price_start = $fvPrice['price_start'];
- echo " cena: ".$price_start." (".$fvPrice['document_no'].")
";
- }
+ // invoice price?
+ $fvPrice = $db->fetchByAssoc($db->query("
+ SELECT i.id, i.document_no, ii.price_start, ii.ecmvat_value, ii.ecmvat_name, ii.ecmvat_id
+ FROM ecminvoiceoutitems AS ii
+ INNER JOIN ecminvoiceouts AS i
+ ON i.id = ii.ecminvoiceout_id
+ WHERE
+ i.parent_id= '1b9643ca-5b1a-8f9b-b809-586b5619b068' AND
+ i.currency_id = 'PLN' AND
+ ii.ecmproduct_id = '$p->id'
+ ORDER BY i.register_date DESC
+ LIMIT 0,1
+ "));
+
+ if (!isset($fvPrice)) {
+ $price_start = 0;
+ echo " Brak ceny
";
+ } else {
+ $price_start = $fvPrice['price_start'];
+ echo " Cena: ".$price_start." (".$fvPrice['document_no'].")
";
+ }
+ }
$prod = array();
@@ -176,7 +188,6 @@
NIP: ".$sale->shipping_nip."
ILN: ".$sale->shipping_iln;
-
$newId = $new->save(true);
//update E5 number in Twinpol
diff --git a/include/language/en_us.EcmDropdownEditor.php b/include/language/en_us.EcmDropdownEditor.php
index d78ef481..300bbdbd 100644
--- a/include/language/en_us.EcmDropdownEditor.php
+++ b/include/language/en_us.EcmDropdownEditor.php
@@ -1,5 +1,5 @@
array (
@@ -75,6 +75,7 @@ $customDoms = array (
'225115e4-1ce2-9a98-b7a0-672930e3318c' => 'Blister tabletki 10szt. 2 g',
'e6900d92-6fde-90e6-b872-67d1938745e6' => 'Słoik 400 ml',
'e3e0c9da-6d08-e1e0-b9ba-67eaa437cb84' => 'Bottle B1_30ml',
+ '8bcf43bf-7b49-5dbf-6b86-67f6c12b82d7' => 'Softpack',
),
'ecmproducts_brand_dom' =>
array (
@@ -163,6 +164,7 @@ $customDoms = array (
'661388b9-ac42-d5a8-2503-67b856a06f52' => 'Coffeeano',
'1f9d4c5d-670e-4c77-d4de-67cddc908559' => 'DeCal',
'5c883b90-f1fb-83d1-6347-67dbd49469f0' => 'EntertainME',
+ 'b1df2c57-aef2-290f-c207-67f7916afed9' => 'Mistify',
),
'ecmproducts_category_dom' =>
array (
diff --git a/include/language/pl_pl.EcmDropdownEditor.php b/include/language/pl_pl.EcmDropdownEditor.php
index 8d0c8b8a..965b2180 100644
--- a/include/language/pl_pl.EcmDropdownEditor.php
+++ b/include/language/pl_pl.EcmDropdownEditor.php
@@ -1,5 +1,5 @@
array (
@@ -75,6 +75,7 @@ $customDoms = array (
'225115e4-1ce2-9a98-b7a0-672930e3318c' => 'Blister tabletki 10szt. 2 g',
'e6900d92-6fde-90e6-b872-67d1938745e6' => 'Słoik 400 ml',
'e3e0c9da-6d08-e1e0-b9ba-67eaa437cb84' => 'Butelka B1_30ml',
+ '8bcf43bf-7b49-5dbf-6b86-67f6c12b82d7' => 'Softpack',
),
'ecmproducts_brand_dom' =>
array (
@@ -163,6 +164,7 @@ $customDoms = array (
'661388b9-ac42-d5a8-2503-67b856a06f52' => 'Coffeeano',
'1f9d4c5d-670e-4c77-d4de-67cddc908559' => 'DeCal',
'5c883b90-f1fb-83d1-6347-67dbd49469f0' => 'EntertainME',
+ 'b1df2c57-aef2-290f-c207-67f7916afed9' => 'Mistify',
),
'ecmproducts_category_dom' =>
array (
diff --git a/modules/EcmInvoiceOuts/EcmInvoiceOut.php b/modules/EcmInvoiceOuts/EcmInvoiceOut.php
index b69408bb..ea0b7006 100644
--- a/modules/EcmInvoiceOuts/EcmInvoiceOut.php
+++ b/modules/EcmInvoiceOuts/EcmInvoiceOut.php
@@ -114,9 +114,11 @@ class EcmInvoiceOut extends SugarBean {
var $user;
var $mfp;
var $canceled;
- // added 4.03.2009
var $pricebook_id;
var $show_recipient_code;
+ var $total_netto;
+ var $total_brutto;
+ var $vats_summary;
// RELATED FIELDS
var $created_by;
var $created_by_name;
diff --git a/modules/EcmProducts/EcmProduct.php b/modules/EcmProducts/EcmProduct.php
index 1e7d95b2..012de61d 100755
--- a/modules/EcmProducts/EcmProduct.php
+++ b/modules/EcmProducts/EcmProduct.php
@@ -1,5 +1,5 @@
setupCustomFields('EcmProducts');
- foreach ($this->field_defs as $field)
- {
- $this->field_name_map[$field['name']] = $field;
- }
- }
-
- var $new_schema = true;
-
- function get_summary_text(){
- return "$this->name";
- }
-
- function create_list_query($order_by, $where, $show_deleted = 0){
-// Fill in the assigned_user_name
- $custom_join = $this->custom_fields->getJOIN();
- $query = "SELECT ";
- $query .= "
+ );
+
+ function EcmProduct()
+ {
+ parent::SugarBean();
+ $this->setupCustomFields('EcmProducts');
+ foreach ($this->field_defs as $field) {
+ $this->field_name_map[$field['name']] = $field;
+ }
+ }
+
+ var $new_schema = true;
+
+ function get_summary_text()
+ {
+ return "$this->name";
+ }
+
+ function create_list_query($order_by, $where, $show_deleted = 0)
+ {
+ // Fill in the assigned_user_name
+ $custom_join = $this->custom_fields->getJOIN();
+ $query = "SELECT ";
+ $query .= "
ecmproducts.*
,users.user_name as assigned_user_name";
- if($custom_join){
- $query .= $custom_join['select'];
- }
- $query .= " FROM ecmproducts
+ if ($custom_join) {
+ $query .= $custom_join['select'];
+ }
+ $query .= " FROM ecmproducts
LEFT JOIN users
ON ecmproducts.assigned_user_id=users.id";
-
- $query .= " ";
- if($custom_join){
- $query .= $custom_join['join'];
- }
- $where_auto = '1=1';
- if($show_deleted == 0){
- $where_auto = " $this->table_name.deleted=0 ";
- }else if($show_deleted == 1){
- $where_auto = " $this->table_name.deleted=1 ";
- }
-
- if($where != "")
- $query .= "where $where AND ".$where_auto;
- else
- $query .= "where ".$where_auto;
- if(substr_count($order_by, '.') > 0){
- $query .= " ORDER BY $order_by";
- }
- else if($order_by != "")
- $query .= " ORDER BY $order_by";
- else
- $query .= " ORDER BY ecmproducts.name";
-
- return $query;
- }
- function create_export_query($order_by, $where){
- $custom_join = $this->custom_fields->getJOIN();
- $query = "SELECT
+ $query .= " ";
+ if ($custom_join) {
+ $query .= $custom_join['join'];
+ }
+ $where_auto = '1=1';
+ if ($show_deleted == 0) {
+ $where_auto = " $this->table_name.deleted=0 ";
+ } else if ($show_deleted == 1) {
+ $where_auto = " $this->table_name.deleted=1 ";
+ }
+
+ if ($where != "")
+ $query .= "where $where AND " . $where_auto;
+ else
+ $query .= "where " . $where_auto;
+ if (substr_count($order_by, '.') > 0) {
+ $query .= " ORDER BY $order_by";
+ } else if ($order_by != "")
+ $query .= " ORDER BY $order_by";
+ else
+ $query .= " ORDER BY ecmproducts.name";
+
+ return $query;
+ }
+
+ function create_export_query($order_by, $where)
+ {
+ $custom_join = $this->custom_fields->getJOIN();
+ $query = "SELECT
ecmproducts.*,
users.user_name assigned_user_name";
- if($custom_join){
- $query .= $custom_join['select'];
- }
- $query .= " FROM ecmproducts ";
-
- $query .= " LEFT JOIN users
+ if ($custom_join) {
+ $query .= $custom_join['select'];
+ }
+ $query .= " FROM ecmproducts ";
+
+ $query .= " LEFT JOIN users
ON ecmproducts.assigned_user_id=users.id";
- if($custom_join){
- $query .= $custom_join['join'];
- }
- $query .= "";
- $where_auto = " ecmproducts.deleted=0
+ if ($custom_join) {
+ $query .= $custom_join['join'];
+ }
+ $query .= "";
+ $where_auto = " ecmproducts.deleted=0
";
-
- if($where != "")
- $query .= " where $where AND ".$where_auto;
- else
- $query .= " where ".$where_auto;
-
- if($order_by != "")
- $query .= " ORDER BY $order_by";
- else
- $query .= " ORDER BY ecmproducts.name";
-
- return $query;
- }
-
- function fill_in_additional_list_fields(){
- }
-
- function fill_in_additional_detail_fields(){
-// FILL IN THE ASSIGNED_USER_NAME
- $this->assigned_user_name = get_assigned_user_name($this->assigned_user_id);
- $this->created_by_name = get_assigned_user_name($this->created_by);
- $this->modified_by_name = get_assigned_user_name($this->modified_user_id);
+ if ($where != "")
+ $query .= " where $where AND " . $where_auto;
+ else
+ $query .= " where " . $where_auto;
- if ($_REQUEST['action '] == 'DetailView') {
- $this->url1 = ''.$this->url1.'';
- $this->url2 = ''.$this->url2.'';
- $this->url3 = ''.$this->url3.'';
- $this->url4 = ''.$this->url4.'';
- $this->url5 = ''.$this->url5.'';
- $this->url6 = ''.$this->url6.'';
- $this->url7 = ''.$this->url7.'';
- $this->url8 = ''.$this->url8.'';
- $this->url9 = ''.$this->url9.'';
+ if ($order_by != "")
+ $query .= " ORDER BY $order_by";
+ else
+ $query .= " ORDER BY ecmproducts.name";
+
+ return $query;
}
-
- //$r = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("SELECT SUM(quantity) as qty FROM ecmstockstates WHERE product_id='".$this->id."'"));
- //$this->ems_qty_in_stock = $r['qty'];
- }
- function getSale($date){
- foreach($date as $d){
- $z="select
+
+ function fill_in_additional_list_fields() {}
+
+ function fill_in_additional_detail_fields()
+ {
+ // FILL IN THE ASSIGNED_USER_NAME
+ $this->assigned_user_name = get_assigned_user_name($this->assigned_user_id);
+ $this->created_by_name = get_assigned_user_name($this->created_by);
+ $this->modified_by_name = get_assigned_user_name($this->modified_user_id);
+
+
+ if ($_REQUEST['action '] == 'DetailView') {
+ $this->url1 = '' . $this->url1 . '';
+ $this->url2 = '' . $this->url2 . '';
+ $this->url3 = '' . $this->url3 . '';
+ $this->url4 = '' . $this->url4 . '';
+ $this->url5 = '' . $this->url5 . '';
+ $this->url6 = '' . $this->url6 . '';
+ $this->url7 = '' . $this->url7 . '';
+ $this->url8 = '' . $this->url8 . '';
+ $this->url9 = '' . $this->url9 . '';
+ }
+
+ //$r = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("SELECT SUM(quantity) as qty FROM ecmstockstates WHERE product_id='".$this->id."'"));
+ //$this->ems_qty_in_stock = $r['qty'];
+ }
+ function getSale($date)
+ {
+ foreach ($date as $d) {
+ $z = "select
sum(
CASE WHEN e.type!='correct'
THEN
@@ -372,11 +374,11 @@ class EcmProduct extends SugarBean {
left join ecmstockdocouts as w on e.wz_id=w.id
left join ecmproducts as p on p.id=i.ecmproduct_id
where
- e.register_date like '".$d."%' and e.status='accepted' and i.ecmproduct_id='".$this->id."'";
- $r=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query($z));
- $total_s+=$r['sales'];
- $total_p+=$r['purchase'];
- $total_q+=$r['quantity'];
+ e.register_date like '" . $d . "%' and e.status='accepted' and i.ecmproduct_id='" . $this->id . "'";
+ $r = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query($z));
+ $total_s += $r['sales'];
+ $total_p += $r['purchase'];
+ $total_q += $r['quantity'];
/*$r=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select sum(i.quantity) as q,sum(i.quantity*i.price) as s,sum(i.quantity*i.purchase_price) as p from ecminvoiceouts as e inner join ecminvoiceoutitems as i on i.ecminvoiceout_id=e.id where e.register_date like '".$d."%' and e.status='accepted' and i.ecmproduct_id='".$this->id."'"));
$total_s+=$r['s'];
$total_p+=$r['p'];
@@ -393,77 +395,74 @@ class EcmProduct extends SugarBean {
}*/
}
//echo $total_s." ".$total_p." ".$total_q."
";
- return array("sale"=>$total_s,"purchase"=>$total_p,"quantity"=>$total_q);
-
- }
-
- function get_list_view_data(){
- global $current_language,$current_user;
- global $numerek;
- $numerek=$this->id;
- $i=0;
- $i++;
- $the_array = parent::get_list_view_data();
- $app_list_strings = return_app_list_strings_language($current_language);
- $mod_strings = return_module_language($current_language, 'EcmProducts');
- global $current_user_id;
-
- $r = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("SELECT SUM(quantity) as qty FROM ecmstockstates WHERE product_id='".$this->id."'"));
- $this->ems_qty_in_stock = $r['qty'];
- // THE NEW LISTVIEW CODE ONLY FETCHES COLUMNS THAT WE'RE DISPLAYING AND NOT ALL
- // THE COLUMNS SO WE NEED THESE CHECKS.
- $the_array['NAME'] = (($this->name == "") ? "blank" : $this->name);
- //chmod('modules/EcmProducts/upload/images/'.$this->product_picture,777);
- if(file_exists('modules/EcmProducts/upload/images/'.$this->product_picture) && $this->product_picture){
- $the_array['IMAGE']='
';
-
- }
- $the_array['STOCK_QTY'] = 0;
- $op=new EcmStockOperation();
- $the_array['STOCK_QTY']=format_number($op->getAllQuantity($this->id));
- $the_array['ENCODED_NAME'] = $this->name;
- $lolek=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select sum(pp.product_quantity) as l from ecmproducts_ecmpurchaseorders as pp inner join ecmpurchaseorders as p on p.id=pp.ecmpurchaseorder_id where pp.ecmproduct_id='".$this->id."' and p.status='accepted' and p.deleted='0'"));
+ return array("sale" => $total_s, "purchase" => $total_p, "quantity" => $total_q);
+ }
- //echo "select sum(pp.product_quantity) as l from ecmproducts_ecmpurchaseorders as pp inner join ecmpurchaseorders as p on p.id=pp.ecmpurchaseorder_id where pp.ecmproduct_id='".$this->id."' and p.status='accepted'
";
-
- $the_array['ORDERED']=$lolek['l'];
- $the_array['SRP_PRICE'] = number_format($this->srp_price,2,$GLOBALS['sugar_config']['default_decimal_seperator'],$GLOBALS['sugar_config']['default_number_grouping_seperator']);
- $the_array['EDIT_BTN'] = '
';
- $the_array['PURCHASE_PRICE'] = number_format($this->purchase_price,2,$GLOBALS['sugar_config']['default_decimal_seperator'],$GLOBALS['sugar_config']['default_number_grouping_seperator']);
- $the_array['COMMISSION_RATE'] = number_format($this->commission_rate,2,$GLOBALS['sugar_config']['default_decimal_seperator'],$GLOBALS['sugar_config']['default_number_grouping_seperator']);
- if($_SESSION[$current_user->user_name.'_PREFERENCES']['global']['EcmProductsQ']['stock_id_basic']){
- $sid=$_SESSION[$current_user->user_name.'_PREFERENCES']['global']['EcmProductsQ']['stock_id_basic'];
- $st=" and stock_id='".$sid."'";
- }
- elseif($_SESSION[$current_user->user_name.'_PREFERENCES']['global']['EcmProductsQ']['stock_id_advanced']) {
- $sid=$_SESSION[$current_user->user_name.'_PREFERENCES']['global']['EcmProductsQ']['stock_id_advanced'];
- $st=" and stock_id='".$sid."'";
- }
- else $st="";
- $this->retrieve($this->id);
-
+ function get_list_view_data()
+ {
+ global $current_language, $current_user;
+ global $numerek;
+ $numerek = $this->id;
+ $i = 0;
+ $i++;
+ $the_array = parent::get_list_view_data();
+ $app_list_strings = return_app_list_strings_language($current_language);
+ $mod_strings = return_module_language($current_language, 'EcmProducts');
+ global $current_user_id;
- if (!$this->code) $this->code='--';
-
- if ($_REQUEST['action']=='ListView' || $_REQUEST['action']=='index') {
- if ($this->product_active) {
- if($this->status=='active'){
- $the_array['CODE']='
'.$this->code.'
';
+ $r = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("SELECT SUM(quantity) as qty FROM ecmstockstates WHERE product_id='" . $this->id . "'"));
+ $this->ems_qty_in_stock = $r['qty'];
+ // THE NEW LISTVIEW CODE ONLY FETCHES COLUMNS THAT WE'RE DISPLAYING AND NOT ALL
+ // THE COLUMNS SO WE NEED THESE CHECKS.
+ $the_array['NAME'] = (($this->name == "") ? "blank" : $this->name);
+ //chmod('modules/EcmProducts/upload/images/'.$this->product_picture,777);
+ if (file_exists('modules/EcmProducts/upload/images/' . $this->product_picture) && $this->product_picture) {
+ $the_array['IMAGE'] = '
';
}
- if($this->status=='new'){
- $the_array['CODE']=''.$this->code.'
';
- }
- if($this->status=='end_of_line'){
- $the_array['CODE']=''.$this->code.'
';
- }
- if(!$this->status){
- $the_array['CODE']=''.$this->code.'
';
- }
- } else
- $the_array['CODE']=''.$this->code.'
';
- }
+ $the_array['STOCK_QTY'] = 0;
+ $op = new EcmStockOperation();
+ $the_array['STOCK_QTY'] = format_number($op->getAllQuantity($this->id));
+ $the_array['ENCODED_NAME'] = $this->name;
+ $lolek = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select sum(pp.product_quantity) as l from ecmproducts_ecmpurchaseorders as pp inner join ecmpurchaseorders as p on p.id=pp.ecmpurchaseorder_id where pp.ecmproduct_id='" . $this->id . "' and p.status='accepted' and p.deleted='0'"));
- /*$z="select sum(quantity) as q from ecmstockstates where product_id='".$this->id."' and deleted='0'".$st;
+ //echo "select sum(pp.product_quantity) as l from ecmproducts_ecmpurchaseorders as pp inner join ecmpurchaseorders as p on p.id=pp.ecmpurchaseorder_id where pp.ecmproduct_id='".$this->id."' and p.status='accepted'
";
+
+ $the_array['ORDERED'] = $lolek['l'];
+ $the_array['SRP_PRICE'] = number_format($this->srp_price, 2, $GLOBALS['sugar_config']['default_decimal_seperator'], $GLOBALS['sugar_config']['default_number_grouping_seperator']);
+ $the_array['EDIT_BTN'] = '
';
+ $the_array['PURCHASE_PRICE'] = number_format($this->purchase_price, 2, $GLOBALS['sugar_config']['default_decimal_seperator'], $GLOBALS['sugar_config']['default_number_grouping_seperator']);
+ $the_array['COMMISSION_RATE'] = number_format($this->commission_rate, 2, $GLOBALS['sugar_config']['default_decimal_seperator'], $GLOBALS['sugar_config']['default_number_grouping_seperator']);
+ if ($_SESSION[$current_user->user_name . '_PREFERENCES']['global']['EcmProductsQ']['stock_id_basic']) {
+ $sid = $_SESSION[$current_user->user_name . '_PREFERENCES']['global']['EcmProductsQ']['stock_id_basic'];
+ $st = " and stock_id='" . $sid . "'";
+ } elseif ($_SESSION[$current_user->user_name . '_PREFERENCES']['global']['EcmProductsQ']['stock_id_advanced']) {
+ $sid = $_SESSION[$current_user->user_name . '_PREFERENCES']['global']['EcmProductsQ']['stock_id_advanced'];
+ $st = " and stock_id='" . $sid . "'";
+ } else $st = "";
+ $this->retrieve($this->id);
+
+
+ if (!$this->code) $this->code = '--';
+
+ if ($_REQUEST['action'] == 'ListView' || $_REQUEST['action'] == 'index') {
+ if ($this->product_active) {
+ if ($this->status == 'active') {
+ $the_array['CODE'] = '' . $this->code . '
';
+ }
+ if ($this->status == 'new') {
+ $the_array['CODE'] = '' . $this->code . '
';
+ }
+ if ($this->status == 'end_of_line') {
+ $the_array['CODE'] = '' . $this->code . '
';
+ }
+ if (!$this->status) {
+ $the_array['CODE'] = '' . $this->code . '
';
+ }
+ } else
+ $the_array['CODE'] = '' . $this->code . '
';
+ }
+
+ /*$z="select sum(quantity) as q from ecmstockstates where product_id='".$this->id."' and deleted='0'".$st;
$w=$GLOBALS['db']->query($z);
$qq=0;
$r=$GLOBALS['db']->fetchByAssoc($w);
@@ -471,9 +470,9 @@ class EcmProduct extends SugarBean {
- $the_array['EMS_QTY_IN_STOCK']=number_format($this->ems_qty_in_stock,0,"","");
-
- /*
+ $the_array['EMS_QTY_IN_STOCK'] = number_format($this->ems_qty_in_stock, 0, "", "");
+
+ /*
include_once("modules/EcmProductReports/vtigerConnector.php");
$vc=new vtigerConnector();
$vc->where="poproductrel.productcode like '".$this->code."'";
@@ -485,156 +484,162 @@ class EcmProduct extends SugarBean {
$ord+=$data[$i]['quantity'];
}
*/
- $r=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select * from ecmproducts where id='".$this->id."'"));
-
- $rp_sum=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select sum(p.product_quantity) as s from ecmproducts_ecmpurchaseorders as p inner join ecmpurchaseorders as e on e.id=p.ecmpurchaseorder_id where p.ecmproduct_id='".$this->id."' and p.deleted='0' and e.deleted='0'"));
- $rp_app=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select sum(p.product_quantity) as s from ecmproducts_ecmpurchaseorders as p inner join ecmpurchaseorders as e on e.id=p.ecmpurchaseorder_id where p.ecmproduct_id='".$this->id."' and p.deleted='0' and (e.status='accepted' or e.status='mailed') and e.deleted='0'"));
- $rp_cr=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select sum(p.product_quantity) as s from ecmproducts_ecmpurchaseorders as p inner join ecmpurchaseorders as e on e.id=p.ecmpurchaseorder_id where p.ecmproduct_id='".$this->id."' and p.deleted='0' and e.status='not_accepted' and e.deleted='0'"));
+ $r = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select * from ecmproducts where id='" . $this->id . "'"));
- $the_array['ORD_CREATED']=$rp_cr['s'];
- $the_array['ORD_APPROVED']=$rp_app['s'];
- //$the_array['ORDERED']=$rp_app['s']+$rp_cr['s'];
- //$the_array['ORD_DELIVERED']=$r['ord_delivered'];
+ $rp_sum = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select sum(p.product_quantity) as s from ecmproducts_ecmpurchaseorders as p inner join ecmpurchaseorders as e on e.id=p.ecmpurchaseorder_id where p.ecmproduct_id='" . $this->id . "' and p.deleted='0' and e.deleted='0'"));
+ $rp_app = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select sum(p.product_quantity) as s from ecmproducts_ecmpurchaseorders as p inner join ecmpurchaseorders as e on e.id=p.ecmpurchaseorder_id where p.ecmproduct_id='" . $this->id . "' and p.deleted='0' and (e.status='accepted' or e.status='mailed') and e.deleted='0'"));
+ $rp_cr = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select sum(p.product_quantity) as s from ecmproducts_ecmpurchaseorders as p inner join ecmpurchaseorders as e on e.id=p.ecmpurchaseorder_id where p.ecmproduct_id='" . $this->id . "' and p.deleted='0' and e.status='not_accepted' and e.deleted='0'"));
- $the_array['Q0']=round($r['q0']);
- $the_array['Q3']=round(($r['q3']));
+ $the_array['ORD_CREATED'] = $rp_cr['s'];
+ $the_array['ORD_APPROVED'] = $rp_app['s'];
+ //$the_array['ORDERED']=$rp_app['s']+$rp_cr['s'];
+ //$the_array['ORD_DELIVERED']=$r['ord_delivered'];
- $the_array['S0']=number_format($r['s0'],2,",",".");
- $the_array['S3']=number_format($r['s3'],2,",",".");
+ $the_array['Q0'] = round($r['q0']);
+ $the_array['Q3'] = round(($r['q3']));
- $the_array['P0']=number_format($r['p0'],2,",",".");
- $the_array['P3']=number_format($r['p3'],2,",",".");
-
- $stock_value=($this->ems_price*$this->ems_qty_in_stock);
- $the_array['STOCK_VALUE']=number_format($stock_value,2,",",".");
-
- if(round(($r['s3']))!=0)$stock_month=(($this->ems_qty_in_stock+$this->ordered)/round(($r['s3'])));
- else $stock_month=0;
- $the_array['STOCK_MONTH']=number_format($stock_month,2,",",".");
-
- $the_array['EMS_PRICE']=number_format($this->ems_price,2,",",".");
- $r=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select flag from ecmproducts where id='".$this->id."'"));
- if($this->flag){
- $flag=0;
- $color="red";
- }
- else {
- $flag=1;
- $color="#cccccc";
- }
- $the_array['FLAGS']='!';
-
- $the_array['HINT']=HintProduct($this->id,$this->description,$this->add_status);
-
- // $the_array['TO_ORDER'] = $r['to']
+ $the_array['S0'] = number_format($r['s0'], 2, ",", ".");
+ $the_array['S3'] = number_format($r['s3'], 2, ",", ".");
- $the_array['STAN']="".($this->active?'Tak':'Nie')."";
+ $the_array['P0'] = number_format($r['p0'], 2, ",", ".");
+ $the_array['P3'] = number_format($r['p3'], 2, ",", ".");
- //$GLOBALS['db']->query("update ecmproducts set q0='".$s0['quantity']."',p0='".($s0['sale']-$s0['purchase'])."',s0='".$s0['sale']."',q3='".($s3['quantity']/3)."',p3='".(($s3['sale']-$s3['purchase'])/3)."',s3='".($s3['sale']/3)."',stock_month='".$stock_month."',stock_value='".$stock_value."' where id='".$this->id."'");
- //echo mysql_error();
- // echo $i;
- return $the_array;
- }
-
- /**
+ $stock_value = ($this->ems_price * $this->ems_qty_in_stock);
+ $the_array['STOCK_VALUE'] = number_format($stock_value, 2, ",", ".");
+
+ if (round(($r['s3'])) != 0) $stock_month = (($this->ems_qty_in_stock + $this->ordered) / round(($r['s3'])));
+ else $stock_month = 0;
+ $the_array['STOCK_MONTH'] = number_format($stock_month, 2, ",", ".");
+
+ $the_array['EMS_PRICE'] = number_format($this->ems_price, 2, ",", ".");
+ $r = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select flag from ecmproducts where id='" . $this->id . "'"));
+ if ($this->flag) {
+ $flag = 0;
+ $color = "red";
+ } else {
+ $flag = 1;
+ $color = "#cccccc";
+ }
+ $the_array['FLAGS'] = '!';
+
+ $the_array['HINT'] = HintProduct($this->id, $this->description, $this->add_status);
+
+ // $the_array['TO_ORDER'] = $r['to']
+
+ $the_array['STAN'] = "" . ($this->active ? 'Tak' : 'Nie') . "";
+
+ //$GLOBALS['db']->query("update ecmproducts set q0='".$s0['quantity']."',p0='".($s0['sale']-$s0['purchase'])."',s0='".$s0['sale']."',q3='".($s3['quantity']/3)."',p3='".(($s3['sale']-$s3['purchase'])/3)."',s3='".($s3['sale']/3)."',stock_month='".$stock_month."',stock_value='".$stock_value."' where id='".$this->id."'");
+ //echo mysql_error();
+ // echo $i;
+ return $the_array;
+ }
+
+ /**
BUILDS A GENERIC SEARCH BASED ON THE QUERY STRING USING OR.
DO NOT INCLUDE ANY $THIS-> BECAUSE THIS IS CALLED ON WITHOUT HAVING THE CLASS INSTANTIATED.
- */
- function build_generic_where_clause ($the_query_string) {
- $where_clauses = Array();
- $the_query_string = PearDatabase::quote(from_html($the_query_string));
- array_push($where_clauses, "ecmproducts.name like '$the_query_string%'");
-
- $the_where = "";
- foreach($where_clauses as $clause){
- if($the_where != "") $the_where .= " or ";
- $the_where .= $clause;
- }
- return $the_where;
- }
-
- function set_notification_body($xtpl, $simplemodule){
- global $mod_strings, $app_list_strings;
-
- $xtpl->assign("NAME", $simplemodule->name);
- $xtpl->assign("ECMPRODUCTS_DESCRIPTION", $ecmproducts->description);
- return $xtpl;
- }
-
- function bean_implements($interface){
- switch($interface){
- case 'ACL':return true;
- }
- return false;
- }
- function r($t){
- $t=str_replace(".","",$t);
- $t=str_replace(",",".",$t);
- $t=floatval($t);
- return $t;
- }
- function save($check_notify = FALSE){
+ */
+ function build_generic_where_clause($the_query_string)
+ {
+ $where_clauses = array();
+ $the_query_string = PearDatabase::quote(from_html($the_query_string));
+ array_push($where_clauses, "ecmproducts.name like '$the_query_string%'");
+
+ $the_where = "";
+ foreach ($where_clauses as $clause) {
+ if ($the_where != "") $the_where .= " or ";
+ $the_where .= $clause;
+ }
+ return $the_where;
+ }
+
+ function set_notification_body($xtpl, $simplemodule)
+ {
+ global $mod_strings, $app_list_strings;
+
+ $xtpl->assign("NAME", $simplemodule->name);
+ $xtpl->assign("ECMPRODUCTS_DESCRIPTION", $ecmproducts->description);
+ return $xtpl;
+ }
+
+ function bean_implements($interface)
+ {
+ switch ($interface) {
+ case 'ACL':
+ return true;
+ }
+ return false;
+ }
+ function r($t)
+ {
+ $t = str_replace(".", "", $t);
+ $t = str_replace(",", ".", $t);
+ $t = floatval($t);
+ return $t;
+ }
+ function save($check_notify = FALSE)
+ {
include("modules/EcmProducts/generateEAN.php");
- if ($_REQUEST['newEan']=='1') $_REQUEST['ean']=generateEan(1);
- if ($_REQUEST['newEan2']=='1') $this->ean2 = generateEAN(2);
+ if ($_REQUEST['newEan'] == '1') $_REQUEST['ean'] = generateEan(1);
+ if ($_REQUEST['newEan2'] == '1') $this->ean2 = generateEAN(2);
//$_REQUEST['ean2'] = generateEan(1);
-
-
- if($_REQUEST['massupdate']){
- foreach($_REQUEST['mass'] as $m)$mm[]="id='".$m."'";
- if($_REQUEST['production'])$set[]="production='".$_REQUEST['production']."'";
- if($_REQUEST['product_active'])$set[]="product_active='".$_REQUEST['product_active']."'";
- if($_REQUEST['end_of_line'])$set[]="end_of_line='".$_REQUEST['end_of_line']."'";
- if($_REQUEST['sales_start_date'])$set[]="sales_start_date='".date("Y-m-d",strtotime($GLOBALS['timedate']->to_db_date($_REQUEST['sales_start_date']))+24*3600)."'";
- if($_REQUEST['sales_end_date'])$set[]="sales_end_date='".date("Y-m-d",strtotime($GLOBALS['timedate']->to_db_date($_REQUEST['sales_end_date']))+24*3600)."'";
- if(count($set)>0)$z="update ecmproducts set ".implode(",",$set)." where ".implode(" or ",$mm);
+
+
+ if ($_REQUEST['massupdate']) {
+ foreach ($_REQUEST['mass'] as $m) $mm[] = "id='" . $m . "'";
+ if ($_REQUEST['production']) $set[] = "production='" . $_REQUEST['production'] . "'";
+ if ($_REQUEST['product_active']) $set[] = "product_active='" . $_REQUEST['product_active'] . "'";
+ if ($_REQUEST['end_of_line']) $set[] = "end_of_line='" . $_REQUEST['end_of_line'] . "'";
+ if ($_REQUEST['sales_start_date']) $set[] = "sales_start_date='" . date("Y-m-d", strtotime($GLOBALS['timedate']->to_db_date($_REQUEST['sales_start_date'])) + 24 * 3600) . "'";
+ if ($_REQUEST['sales_end_date']) $set[] = "sales_end_date='" . date("Y-m-d", strtotime($GLOBALS['timedate']->to_db_date($_REQUEST['sales_end_date'])) + 24 * 3600) . "'";
+ if (count($set) > 0) $z = "update ecmproducts set " . implode(",", $set) . " where " . implode(" or ", $mm);
//echo $z;
$GLOBALS['db']->query($z);
header("Location: index.php?module=EcmProducts&action=index");
- }
- else{
- $return_id = parent::save($check_notify);
-
- //$components = self::ParseComponentsFromPOST();
- //if(!(!is_array($components) && $components == false)) $this->position_list = $components;
- //$this->savePositions($return_id);
-
- //save categories
- $this->savePositions3($_POST['position_list3']);
- //save prices
- $this->savePrices($_POST['position_list4']);
-
-
- return $return_id;
- }
- }
+ } else {
+ $return_id = parent::save($check_notify);
+
+ //$components = self::ParseComponentsFromPOST();
+ //if(!(!is_array($components) && $components == false)) $this->position_list = $components;
+ //$this->savePositions($return_id);
+
+ //save categories
+ $this->savePositions3($_POST['position_list3']);
+ //save prices
+ $this->savePrices($_POST['position_list4']);
- static function ParseComponentsFromPOST() {
- if(isset($_POST['position_list'])) {
+ return $return_id;
+ }
+ }
+
+
+ static function ParseComponentsFromPOST()
+ {
+ if (isset($_POST['position_list'])) {
$c_ = $_POST['position_list'];
$json = getJSONobj();
$c = $json->decode(htmlspecialchars_decode($c_));
return $c;
- }
- return false;
- }
-//***************************Start Managing Positions*************************//
- function constructInsertQuery($data, $table = '') {
-
- if($table == '' && isset($this->object_name) && $this->object_name != '') {
- $table = strtolower($this->object_name)."components";
+ }
+ return false;
+ }
+ //***************************Start Managing Positions*************************//
+ function constructInsertQuery($data, $table = '')
+ {
+
+ if ($table == '' && isset($this->object_name) && $this->object_name != '') {
+ $table = strtolower($this->object_name) . "components";
} else return "";
-
+
$keys = array();
$values = array();
- foreach($data as $key => $value) {
+ foreach ($data as $key => $value) {
$keys[] = $key;
- if(is_array($value))
- $values[] = $value[1].str_replace("'", "\'", $value[0]).$value[1];
+ if (is_array($value))
+ $values[] = $value[1] . str_replace("'", "\'", $value[0]) . $value[1];
else
- $values[] = "'".str_replace("'", "\'", $value)."'";
+ $values[] = "'" . str_replace("'", "\'", $value) . "'";
}
$q = "insert into `$table` (`";
@@ -642,27 +647,28 @@ class EcmProduct extends SugarBean {
$q .= "`) values (";
$q .= implode(", ", $values);
$q .= ");";
-
- return $q;
+
+ return $q;
}
- function savePositions($id = null, $position_list = null) {
-
+ function savePositions($id = null, $position_list = null)
+ {
+
global $current_user, $timedate;
-
- if($position_list == null) $position_list = $this->position_list;
- if($id == null) $id = $this->id;
-
- if(count($position_list) > 0) $this->deleteAssignedPositions($id);
-
+
+ if ($position_list == null) $position_list = $this->position_list;
+ if ($id == null) $id = $this->id;
+
+ if (count($position_list) > 0) $this->deleteAssignedPositions($id);
+
$arr = array();
$position = 0;
-
- for($i = 0; $i < count($position_list); $i ++) {
- if($position_list[$i]['name'] == '') continue;
-
+ for ($i = 0; $i < count($position_list); $i++) {
+
+ if ($position_list[$i]['name'] == '') continue;
+
$p = $position_list[$i];
-
+
/* Not Nessesary
require_once("modules/EcmVats/EcmVat.php");
$vats = new EcmVat();
@@ -681,9 +687,9 @@ class EcmProduct extends SugarBean {
$p['category_id'] = $pr->product_category_id;
}
*/
-
+
$arr = array(
-
+
'id' => create_guid(),
'date_entered' => array('NOW()', ''),
'date_modified' => array('NOW()', ''),
@@ -691,14 +697,14 @@ class EcmProduct extends SugarBean {
'assigned_user_id' => $current_user->id,
'created_by' => $current_user->id,
'deleted' => '0',
- strtolower($this->object_name).'_id' => $id,
+ strtolower($this->object_name) . '_id' => $id,
'ecmcomponent_id' => $p['id'],
'position' => $position,
'code' => $p['code'],
'name' => $p['name'],
'quantity' => ((empty($p['quantity']) || $p['quantity'] == '') ? 0 : $p['quantity']),
'ecmusageunit_id' => $p['unit_id'],
-
+
/* Not Nessesary
'price' => ((empty($p['price']) || $p['price'] == '') ? 0 : $p['price']),
'discount' => ((empty($p['discount']) || $p['discount'] == '') ? 0 : $p['discount']),
@@ -713,28 +719,28 @@ class EcmProduct extends SugarBean {
'currency_name' => $p['currency_name'],
'recipient_code' => $p['recipient_code'],
*/
-
+
);
-
+
$this->db->query($this->constructInsertQuery($arr));
- $position ++;
- }
-
+ $position++;
+ }
}
- function getPosition($position) {
-
+ function getPosition($position)
+ {
+
global $app_list_strings;
- if(!is_array($position)) return '';
+ if (!is_array($position)) return '';
global $timedate;
-
+
$return_array = array();
- $unit = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select unit_id from ecmproducts where id='".$position['ecmcomponent_id']."'"));
+ $unit = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select unit_id from ecmproducts where id='" . $position['ecmcomponent_id'] . "'"));
$return_array['id'] = $position['ecmcomponent_id'];
$return_array['position'] = $position['position'];
$return_array['code'] = $position['code'];
- $return_array['name'] = str_replace('"','',$position['name']);
+ $return_array['name'] = str_replace('"', '', $position['name']);
$return_array['quantity'] = $position['quantity'];
$return_array['price'] = $position['price'];
$return_array['discount'] = $position['discount'];
@@ -747,310 +753,318 @@ class EcmProduct extends SugarBean {
$return_array['category_id'] = $position['ecmproductcategory_id'];
$return_array['currency_id'] = $position['currency_id'];
$return_array['currency_name'] = $position['currency_name'];
- $return_array['recipient_code'] = $position['recipient_code'];
-
+ $return_array['recipient_code'] = $position['recipient_code'];
+
//get ems price
- $r = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("SELECT ems_price FROM ecmproducts WHERE id='".$position['ecmcomponent_id']."'"));
+ $r = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("SELECT ems_price FROM ecmproducts WHERE id='" . $position['ecmcomponent_id'] . "'"));
$return_array['ems_price'] = $position['quantity'] * $r['ems_price'];
- if (!$r || $r['ems_price']==0) {
+ if (!$r || $r['ems_price'] == 0) {
$pz = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("
SELECT price FROM ecmstockoperations WHERE
-product_id= '".$position['ecmcomponent_id']."' AND
+product_id= '" . $position['ecmcomponent_id'] . "' AND
parent_type = 'EcmStockDocIns'
ORDER BY date_entered DESC
LIMIT 0,1
"));
-
+
$return_array['ems_price'] = $pz['price'];
}
-
+
global $db;
- $c = $db->fetchByAssoc($db->query("SELECT product_category_id as c, purchase_price as p FROM ecmproducts WHERE id='".$position['ecmcomponent_id']."'"));
+ $c = $db->fetchByAssoc($db->query("SELECT product_category_id as c, purchase_price as p FROM ecmproducts WHERE id='" . $position['ecmcomponent_id'] . "'"));
$return_array['category_id'] = $c['c'];
if ($c['c'] == 'd7f876b0-1a3d-43a1-7c9b-511ba40df3d1')
$return_array['ems_price'] = $c['p'];
-
- if (!$return_array['ems_price'] || $return_array['ems_price']=="")
+
+ if (!$return_array['ems_price'] || $return_array['ems_price'] == "")
$return_array['ems_price'] = $c['purchase_price'];
return $return_array;
-
}
- function getPositionList($array = false) {
- if(isset($this->id) && $this->id != '') {
- $query = "SELECT * FROM `ecmproductcomponents` WHERE `ecmproduct_id`='".$this->id."' order by position asc";
- $r = $this->db->query($query);
- $return_array = array();
- if($r) {
- while($w = $this->db->fetchByAssoc($r)) {
- $return_array [] = $this->getPosition($w);
- }
- $json = getJSONobj();
- return $array ? $return_array : $json->encode($return_array);
- }
- }
- return $array ? false : '[]';
- }
- function deleteAssignedPositions() {
- if(isset($this->id) && $this->id != '') {
- $query = "DELETE FROM `".strtolower($this->object_name)."components` WHERE `".strtolower($this->object_name)."_id`='".$this->id."'";
- $r = $this->db->query($query);
- if($r) return true;
- }
- return false;
- }
-//***************************End Managing Positions*************************//
- //start managing categories
- function savePositions3($pl) {
- global $current_user;
- $exists = array();
-
- $first = true;
- foreach ($pl as $p) {
- if (!isset($p['ecmproductcategory_id']) || $p['ecmproductcategory_id']=='') continue;
- //first position save into main category
- if ($first) {
- $q = "UPDATE ecmproducts set product_category_id='".$p['ecmproductcategory_id']."', product_category_name='".$p['ecmproductcategory_name']."' WHERE id='".$this->id."'";
- $GLOBALS['db']->query($q);
- $first = false;
- }
- if (isset($p['id']) && $p['id']!='') {
- //update exists
- $q = "
- UPDATE ecmproductcategories_bean set
- date_modified = '".date("Y-m-d H:i:s")."',
- modified_user_id = '".$current_user->id."',
- bean_id = '".addslashes($this->id)."',
- ecmproductcategory_id = '".addslashes($p['ecmproductcategory_id'])."',
- position = '".$p['position']."'
- WHERE id = '".$p['id']."'
- ";
-
- $GLOBALS['db']->query($q);
- $exists[] = $p['id'];
-
- } else {
- //insert new record
- $id = create_guid();
- $t = array(
- $id,
- addslashes($p['ecmproductcategory_id']),
- $this->id,
- "EcmProducts",
- date("Y-m-d H:i:s"),
- date("Y-m-d H:i:s"),
- $current_user->id,
- $current_user->id,
- '0',
- $p['position'],
- );
- $q = "INSERT INTO ecmproductcategories_bean VALUES ('".implode("','", $t)."')";
- $GLOBALS['db']->query($q);
- $exists[] = $id;
- }
- }
- //delete old
- $GLOBALS['db']->query("UPDATE ecmproductcategories_bean SET deleted='1', modified_user_id='".$current_user->id."',date_modified = '".date("Y-m-d H:i:s")."' WHERE bean_id='".$this->id."' AND id NOT IN ('".implode("','",$exists)."')");
- }
-
- function getPositionList3($array = false) {
- if(isset($this->id) && $this->id != '') {
- $query = "SELECT * FROM ecmproductcategories_bean WHERE bean_id='".$this->id."' AND deleted='0' AND bean_name='EcmProducts'";
-
- $r = $this->db->query($query);
- $return_array = array();
- if($r) {
-
- while($w = $this->db->fetchByAssoc($r)) {
- //get category name && assigned_file
- $n = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("SELECT name, assigned_file FROM ecmproductcategories WHERE id='".$w['ecmproductcategory_id']."'"));
- $w['ecmproductcategory_name'] = $n['name'];
- $w['assigned_file'] = $n['assigned_file'];
- $return_array [] = $w;
-
- }
- $json = getJSONobj();
-
- return $array ? $return_array : $json->encode($return_array);
- }
- }
- return $array ? false : '[]';
- }
-
- function showPositions3(){
- $arr=$this->getPositionList3(true);
+ function getPositionList($array = false)
+ {
+ if (isset($this->id) && $this->id != '') {
+ $query = "SELECT * FROM `ecmproductcomponents` WHERE `ecmproduct_id`='" . $this->id . "' order by position asc";
+ $r = $this->db->query($query);
+ $return_array = array();
+ if ($r) {
+ while ($w = $this->db->fetchByAssoc($r)) {
+ $return_array[] = $this->getPosition($w);
+ }
+ $json = getJSONobj();
+ return $array ? $return_array : $json->encode($return_array);
+ }
+ }
+ return $array ? false : '[]';
+ }
+ function deleteAssignedPositions()
+ {
+ if (isset($this->id) && $this->id != '') {
+ $query = "DELETE FROM `" . strtolower($this->object_name) . "components` WHERE `" . strtolower($this->object_name) . "_id`='" . $this->id . "'";
+ $r = $this->db->query($query);
+ if ($r) return true;
+ }
+ return false;
+ }
+ //***************************End Managing Positions*************************//
+ //start managing categories
+ function savePositions3($pl)
+ {
+ global $current_user;
+ $exists = array();
-
- global $mod_strings;
- if(count($arr)>0){
- $table='
+ $first = true;
+ foreach ($pl as $p) {
+ if (!isset($p['ecmproductcategory_id']) || $p['ecmproductcategory_id'] == '') continue;
+ //first position save into main category
+ if ($first) {
+ $q = "UPDATE ecmproducts set product_category_id='" . $p['ecmproductcategory_id'] . "', product_category_name='" . $p['ecmproductcategory_name'] . "' WHERE id='" . $this->id . "'";
+ $GLOBALS['db']->query($q);
+ $first = false;
+ }
+ if (isset($p['id']) && $p['id'] != '') {
+ //update exists
+ $q = "
+ UPDATE ecmproductcategories_bean set
+ date_modified = '" . date("Y-m-d H:i:s") . "',
+ modified_user_id = '" . $current_user->id . "',
+ bean_id = '" . addslashes($this->id) . "',
+ ecmproductcategory_id = '" . addslashes($p['ecmproductcategory_id']) . "',
+ position = '" . $p['position'] . "'
+ WHERE id = '" . $p['id'] . "'
+ ";
+
+ $GLOBALS['db']->query($q);
+ $exists[] = $p['id'];
+ } else {
+ //insert new record
+ $id = create_guid();
+ $t = array(
+ $id,
+ addslashes($p['ecmproductcategory_id']),
+ $this->id,
+ "EcmProducts",
+ date("Y-m-d H:i:s"),
+ date("Y-m-d H:i:s"),
+ $current_user->id,
+ $current_user->id,
+ '0',
+ $p['position'],
+ );
+ $q = "INSERT INTO ecmproductcategories_bean VALUES ('" . implode("','", $t) . "')";
+ $GLOBALS['db']->query($q);
+ $exists[] = $id;
+ }
+ }
+ //delete old
+ $GLOBALS['db']->query("UPDATE ecmproductcategories_bean SET deleted='1', modified_user_id='" . $current_user->id . "',date_modified = '" . date("Y-m-d H:i:s") . "' WHERE bean_id='" . $this->id . "' AND id NOT IN ('" . implode("','", $exists) . "')");
+ }
+
+ function getPositionList3($array = false)
+ {
+ if (isset($this->id) && $this->id != '') {
+ $query = "SELECT * FROM ecmproductcategories_bean WHERE bean_id='" . $this->id . "' AND deleted='0' AND bean_name='EcmProducts'";
+
+ $r = $this->db->query($query);
+ $return_array = array();
+ if ($r) {
+
+ while ($w = $this->db->fetchByAssoc($r)) {
+ //get category name && assigned_file
+ $n = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("SELECT name, assigned_file FROM ecmproductcategories WHERE id='" . $w['ecmproductcategory_id'] . "'"));
+ $w['ecmproductcategory_name'] = $n['name'];
+ $w['assigned_file'] = $n['assigned_file'];
+ $return_array[] = $w;
+ }
+ $json = getJSONobj();
+
+ return $array ? $return_array : $json->encode($return_array);
+ }
+ }
+ return $array ? false : '[]';
+ }
+
+ function showPositions3()
+ {
+ $arr = $this->getPositionList3(true);
+
+
+ global $mod_strings;
+ if (count($arr) > 0) {
+ $table = '
- | '.$mod_strings['LBL_CATEGORY_NAME'].'
- | '.$mod_strings['LBL_CATEGORY_ASSIGNED_FILE'].'
+ | ' . $mod_strings['LBL_CATEGORY_NAME'] . '
+ | ' . $mod_strings['LBL_CATEGORY_ASSIGNED_FILE'] . '
|
';
- $i == 0;
- foreach($arr as $a){
- $i++;
- //assigned file
- if ($a['assigned_file']!="" && $a['assigned_file']) {
- $tmp = explode(".", $a['assigned_file']);
- if (end($tmp) == 'jpeg' || end($tmp) == 'jpg' || end($tmp) == 'png' || end($tmp) == 'bmp')
- $af = '
';
- else
- $af = ''.$a['assigned_file'].'';
- }
- $table.='
+ $i == 0;
+ foreach ($arr as $a) {
+ $i++;
+ //assigned file
+ if ($a['assigned_file'] != "" && $a['assigned_file']) {
+ $tmp = explode(".", $a['assigned_file']);
+ if (end($tmp) == 'jpeg' || end($tmp) == 'jpg' || end($tmp) == 'png' || end($tmp) == 'bmp')
+ $af = '
';
+ else
+ $af = '' . $a['assigned_file'] . '';
+ }
+ $table .= '
- | '.$a['ecmproductcategory_name'].' |
+ ' . $a['ecmproductcategory_name'] . ' |
- '.$af.' |
+ ' . $af . ' |
';
- }
- $table.='
';
- }
-
- return $table;
- }
- //end managing categories
- //prices manage
-
- function savePrices($prices) {
- if (!is_array($prices)) return null;
-
- $fields = array('id','ecmprice_id','ecmproduct_id','price');
- $new = array();
- $db = $GLOBALS['db'];
-
-
- foreach ($prices as $p) {
- if (!isset($p['price']) || !isset($p['ecmpricebook_id']) || floatval($p['price'])==0) continue;
-
- $id = create_guid();
- $new[] = $id;
-
- $tmp = array();
- $tmp[] = $id;
- $tmp[] = $p['ecmpricebook_id'];
- $tmp[] = $this->id;
- $tmp[] = floatval($p['price']);
-
- $query = "INSERT INTO ecmprices_ecmproducts (".implode(",", $fields).") VALUES ('".implode("','", $tmp)."')";
-
- $db->query($query);
- }
- $db->query("delete from ecmprices_ecmproducts where ecmproduct_id='".$this->id."' AND id NOT IN ('".implode("','",$new)."')");
- }
-
- function getPricePosition($position) {
- if(!is_array($position)) return '';
-
- global $timedate;
- $query="SELECT id,name FROM ecmpricebooks WHERE id='".$position['ecmpricebook_id']."'";
- $r = $this->db->fetchByAssoc($this->db->query($query));
-
- $return_array = array();
-
- $return_array['price'] = $position['price'];
- $return_array['pricebook_name'] = $r['name'];
- $return_array['pricebook_id'] = $r['id'];
-
- //var_dump($return_array);
- return $return_array;
- }
- function getPricesList($array = false) {
- if(isset($this->id) && $this->id != '') {
- $query = "SELECT p.id as id, p.name as name, pp.price as price FROM ecmprices as p
+ }
+ $table .= '';
+ }
+
+ return $table;
+ }
+ //end managing categories
+ //prices manage
+
+ function savePrices($prices)
+ {
+ if (!is_array($prices)) return null;
+
+ $fields = array('id', 'ecmprice_id', 'ecmproduct_id', 'price');
+ $new = array();
+ $db = $GLOBALS['db'];
+
+
+ foreach ($prices as $p) {
+ if (!isset($p['price']) || !isset($p['ecmpricebook_id']) || floatval($p['price']) == 0) continue;
+
+ $id = create_guid();
+ $new[] = $id;
+
+ $tmp = array();
+ $tmp[] = $id;
+ $tmp[] = $p['ecmpricebook_id'];
+ $tmp[] = $this->id;
+ $tmp[] = floatval($p['price']);
+
+ $query = "INSERT INTO ecmprices_ecmproducts (" . implode(",", $fields) . ") VALUES ('" . implode("','", $tmp) . "')";
+
+ $db->query($query);
+ }
+ $db->query("delete from ecmprices_ecmproducts where ecmproduct_id='" . $this->id . "' AND id NOT IN ('" . implode("','", $new) . "')");
+ }
+
+ function getPricePosition($position)
+ {
+ if (!is_array($position)) return '';
+
+ global $timedate;
+ $query = "SELECT id,name FROM ecmpricebooks WHERE id='" . $position['ecmpricebook_id'] . "'";
+ $r = $this->db->fetchByAssoc($this->db->query($query));
+
+ $return_array = array();
+
+ $return_array['price'] = $position['price'];
+ $return_array['pricebook_name'] = $r['name'];
+ $return_array['pricebook_id'] = $r['id'];
+
+ //var_dump($return_array);
+ return $return_array;
+ }
+ function getPricesList($array = false)
+ {
+ if (isset($this->id) && $this->id != '') {
+ $query = "SELECT p.id as id, p.name as name, pp.price as price FROM ecmprices as p
LEFT JOIN ecmprices_ecmproducts as pp
- ON pp.ecmprice_id=p.id AND pp.ecmproduct_id='".$this->id."'
+ ON pp.ecmprice_id=p.id AND pp.ecmproduct_id='" . $this->id . "'
WHERE p.deleted='0'";
- $r = $this->db->query($query);
- $return_array = array();
- if($r) {
- while($w = $this->db->fetchByAssoc($r)) {
- $tmp = array();
- $tmp['pricebook_id'] = $w['id'];
- $tmp['pricebook_name'] = $w['name'];
- $tmp['price'] = $w['price'];
- $return_array [] = $tmp;
- }
- $json = getJSONobj();
- return $array ? $return_array : $json->encode($return_array);
- }
- }
- return $array ? false : '[]';
- }
-
- function showPrices(){
- $arr=$this->getPricesList(true);
- if(count($arr)>0){
- $table='
+ $r = $this->db->query($query);
+ $return_array = array();
+ if ($r) {
+ while ($w = $this->db->fetchByAssoc($r)) {
+ $tmp = array();
+ $tmp['pricebook_id'] = $w['id'];
+ $tmp['pricebook_name'] = $w['name'];
+ $tmp['price'] = $w['price'];
+ $return_array[] = $tmp;
+ }
+ $json = getJSONobj();
+ return $array ? $return_array : $json->encode($return_array);
+ }
+ }
+ return $array ? false : '[]';
+ }
+
+ function showPrices()
+ {
+ $arr = $this->getPricesList(true);
+ if (count($arr) > 0) {
+ $table = '
| Nazwa
| Wartość
|
';
- foreach($arr as $a){
- $table.='
+ foreach ($arr as $a) {
+ $table .= '
|
- '.$a['pricebook_name'].' |
+ ' . $a['pricebook_name'] . '
- '.format_number($a['price']).' |
+ ' . format_number($a['price']) . '
';
- }
- $table.='
';
- }
-
- return $table;
- }
- //end manage prices
- function getProductResInfo($product_id, $stock_id) {
- $info = array();
- global $db;
-
- require_once('modules/EcmStockOperations/EcmStockOperation.php');
- $op = new EcmStockOperation();
- $info['stock']= $op -> getRealStock($product_id, $stock_id);
- //temp reserwations
- $rr = $db->fetchByAssoc($db->query("SELECT sum(quantity) as s FROM ecmreservations WHERE product_id='$product_id' AND doc_id IS NULL"));
- if (!$rr['s']) $rr['s'] = 0;
- $info['res']= $rr['s'];
- //doc reservations
- $res = $db->query("SELECT quantity, doc_id, doc_type FROM ecmreservations WHERE product_id='$product_id' AND doc_id IS NOT NULL");
-
- if (!is_array($res)==0) return $info;
-
- while ($row = $db->fetchByAssoc($res)) {
- $tmp = array();
- $type = '';
- if ($row['doc_type']=='EcmSales') $type = 'ZS';
- if ($row['doc_type']=='EcmInsideOrders') $type = 'ZW';
- //get document name
- $doc = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("SELECT document_no, parent_name FROM ".strtolower($row['doc_type'])." WHERE id='".$row['doc_id']."'"));
- $tmp[] =''.$type.' '.$doc['document_no'].' - '.$row['quantity'].'  '.$doc['parent_name'];
- }
- $info['docs']=$tmp;
-
- return $info;
- }
-
- //add mz 2014-12-11
- //android mobile functions
-
- //search product by EAN
- //simply try found product_id and executa function below
- static function mobile_getProductInfoByEAN($params) {
- $ean = trim($params['product_ean']);
- if (!$ean || $ean=="")
- return -2;
-
- $db = $GLOBALS['db'];
-
- $prod = $db->fetchByAssoc($db->query("SELECT
+ }
+ $table .= '';
+ }
+
+ return $table;
+ }
+ //end manage prices
+ function getProductResInfo($product_id, $stock_id)
+ {
+ $info = array();
+ global $db;
+
+ require_once('modules/EcmStockOperations/EcmStockOperation.php');
+ $op = new EcmStockOperation();
+ $info['stock'] = $op->getRealStock($product_id, $stock_id);
+ //temp reserwations
+ $rr = $db->fetchByAssoc($db->query("SELECT sum(quantity) as s FROM ecmreservations WHERE product_id='$product_id' AND doc_id IS NULL"));
+ if (!$rr['s']) $rr['s'] = 0;
+ $info['res'] = $rr['s'];
+ //doc reservations
+ $res = $db->query("SELECT quantity, doc_id, doc_type FROM ecmreservations WHERE product_id='$product_id' AND doc_id IS NOT NULL");
+
+ if (!is_array($res) == 0) return $info;
+
+ while ($row = $db->fetchByAssoc($res)) {
+ $tmp = array();
+ $type = '';
+ if ($row['doc_type'] == 'EcmSales') $type = 'ZS';
+ if ($row['doc_type'] == 'EcmInsideOrders') $type = 'ZW';
+ //get document name
+ $doc = $GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("SELECT document_no, parent_name FROM " . strtolower($row['doc_type']) . " WHERE id='" . $row['doc_id'] . "'"));
+ $tmp[] = '' . $type . ' ' . $doc['document_no'] . ' - ' . $row['quantity'] . '  ' . $doc['parent_name'];
+ }
+ $info['docs'] = $tmp;
+
+ return $info;
+ }
+
+ //add mz 2014-12-11
+ //android mobile functions
+
+ //search product by EAN
+ //simply try found product_id and executa function below
+ static function mobile_getProductInfoByEAN($params)
+ {
+ $ean = trim($params['product_ean']);
+ if (!$ean || $ean == "")
+ return -2;
+
+ $db = $GLOBALS['db'];
+
+ $prod = $db->fetchByAssoc($db->query("SELECT
id FROM ecmproducts
WHERE
(TRIM(ean) = '$ean' OR
@@ -1058,29 +1072,31 @@ LIMIT 0,1
deleted = '0'
ORDER BY code
LIMIT 0,1"));
-
- if (!$prod['id'])
- return -3; //product not exist
- else
- return EcmProduct::mobile_getProductInfo(
- array (
- 'product_id' => $prod['id']
- ));
- }
-
-
- //ERROR CODES
- // -2 - wrong paramaters
- // -3 - can't find object
- static function mobile_getProductInfo($params) {
- $app_list_strings = return_app_list_strings_language("pl_pl");
-
- $product_id = $params['product_id'];
- if (!$product_id || $product_id=="")
- return -2;
-
- $db = $GLOBALS['db'];
- $prod = $db->fetchByAssoc($db->query("SELECT
+
+ if (!$prod['id'])
+ return -3; //product not exist
+ else
+ return EcmProduct::mobile_getProductInfo(
+ array(
+ 'product_id' => $prod['id']
+ )
+ );
+ }
+
+
+ //ERROR CODES
+ // -2 - wrong paramaters
+ // -3 - can't find object
+ static function mobile_getProductInfo($params)
+ {
+ $app_list_strings = return_app_list_strings_language("pl_pl");
+
+ $product_id = $params['product_id'];
+ if (!$product_id || $product_id == "")
+ return -2;
+
+ $db = $GLOBALS['db'];
+ $prod = $db->fetchByAssoc($db->query("SELECT
id,
IFNULL(name,'-') AS name,
IFNULL(code,'-') AS code,
@@ -1088,43 +1104,42 @@ LIMIT 0,1
IFNULL(ean2,'-') AS ean2,
IFNULL(unit_id,'-') AS unit_id
FROM ecmproducts WHERE id='$product_id'"));
-
- if (!$prod['id'])
- return -3; //product not exist
-
- //get stocks array
- $stocks = array();
- $res = $db->query("SELECT IFNULL(stock_name, '-') as stock_name, quantity FROM ecmstockstates WHERE product_id = '$product_id' AND deleted = '0' AND quantity IS NOT NULL AND quantity != '0' ORDER BY stock_name;");
-
- while ($row = $db->fetchByAssoc($res)) {
- //format number precision
- if ($prod['unit_id'] == "1")
- $qty = format_number(intval($row['quantity']),0,0);
- else
- $qty = format_number(intval($row['quantity']),4,2);
-
+
+ if (!$prod['id'])
+ return -3; //product not exist
+
+ //get stocks array
+ $stocks = array();
+ $res = $db->query("SELECT IFNULL(stock_name, '-') as stock_name, quantity FROM ecmstockstates WHERE product_id = '$product_id' AND deleted = '0' AND quantity IS NOT NULL AND quantity != '0' ORDER BY stock_name;");
+
+ while ($row = $db->fetchByAssoc($res)) {
+ //format number precision
+ if ($prod['unit_id'] == "1")
+ $qty = format_number(intval($row['quantity']), 0, 0);
+ else
+ $qty = format_number(intval($row['quantity']), 4, 2);
+
$tmp = array();
$tmp['name'] = $row['stock_name'];
$tmp['quantity'] = $qty;
$stocks[] = $tmp;
- }
-
- if (sizeof($stocks) == 1)
- $s = htmlspecialchars_decode(json_encode($stocks), ENT_QUOTES);
- else
- $s = htmlspecialchars_decode(json_encode($stocks), ENT_QUOTES);
-
- $result = array (
- 'code' => $prod['code'],
- 'name' => base64_encode($prod['name']),
- 'id' => $prod['id'],
- 'ean' => $prod['ean'],
- 'ean2' => $prod['ean'],
- 'stockStates' => base64_encode($s),
- 'unit' => $app_list_strings['ecmproducts_unit_dom'][$prod['unit_id']],
- );
+ }
- return $result;
- }
+ if (sizeof($stocks) == 1)
+ $s = htmlspecialchars_decode(json_encode($stocks), ENT_QUOTES);
+ else
+ $s = htmlspecialchars_decode(json_encode($stocks), ENT_QUOTES);
+
+ $result = array(
+ 'code' => $prod['code'],
+ 'name' => base64_encode($prod['name']),
+ 'id' => $prod['id'],
+ 'ean' => $prod['ean'],
+ 'ean2' => $prod['ean'],
+ 'stockStates' => base64_encode($s),
+ 'unit' => $app_list_strings['ecmproducts_unit_dom'][$prod['unit_id']],
+ );
+
+ return $result;
+ }
}
-?>
\ No newline at end of file
diff --git a/modules/EcmSales/EcmSale.php b/modules/EcmSales/EcmSale.php
index be79319e..ee2b310e 100644
--- a/modules/EcmSales/EcmSale.php
+++ b/modules/EcmSales/EcmSale.php
@@ -119,6 +119,24 @@ class EcmSale extends SugarBean
// added 4.03.2009
var $pricebook_id;
var $show_recipient_code;
+ var $vats_summary;
+ var $shipping_address_name;
+ var $shipping_address_street;
+ var $shipping_address_postalcode;
+ var $shipping_address_city;
+ var $shipping_address_country;
+ var $shipping_iln;
+ var $shipping_nip;
+ var $edi_zs_id;
+ var $edi_zs_document_no;
+ var $pdf_text;
+ var $parent_nip;
+ var $parent_iln;
+ var $total_netto;
+ var $total_brutto;
+ var $send_date;
+ var $delivery_date;
+ var $parent_document_no;
// RELATED FIELDS
var $created_by;
var $created_by_name;
diff --git a/modules/EcmStockStates/rebuildStates.php b/modules/EcmStockStates/rebuildStates.php
index ef73d59c..dc34cf25 100755
--- a/modules/EcmStockStates/rebuildStates.php
+++ b/modules/EcmStockStates/rebuildStates.php
@@ -29,12 +29,12 @@ if (isset($_GET['ids'])) {
order by date_entered");
}
-brecho($codes);
-//die();
while($r=$GLOBALS['db']->fetchByAssoc($w)){
if(!in_array($r['stock_id'],$sarr))$sarr[]=$r['stock_id'];
if(!in_array($r['product_id'],$parr))$parr[]=$r['product_id'];
+
+ brecho($r['stock_id'],$r['product_id']);
}
for($i=0;$i