Update REST: copy sale from Twinpol

This commit is contained in:
2025-04-16 18:04:18 +00:00
parent 8095cfe88a
commit 62658a1fbb
7 changed files with 864 additions and 814 deletions

View File

@@ -56,6 +56,17 @@
$gotAllProducts = false;
continue;
} else {
// 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." (<a href=\"https://crm.e5.pl/index.php?module=EcmPriceBooks&action=DetailView&record=3e78ac33-7c46-1b94-0a67-653a17c06f9e\" target=\"new\">Amazon_2023</a>)<br>";
} else {
// 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
@@ -74,7 +85,8 @@
echo " <b>Brak ceny</b><br>";
} else {
$price_start = $fvPrice['price_start'];
echo " cena: ".$price_start." (<a href=\"https://crm.e5.pl/index.php?module=EcmInvoiceOuts&action=DetailView&record=".$fvPrice['id']."\" target=\"new\">".$fvPrice['document_no']."</a>)<br>";
echo " Cena: ".$price_start." (<a href=\"https://crm.e5.pl/index.php?module=EcmInvoiceOuts&action=DetailView&record=".$fvPrice['id']."\" target=\"new\">".$fvPrice['document_no']."</a>)<br>";
}
}
$prod = array();
@@ -176,7 +188,6 @@
NIP: ".$sale->shipping_nip."
ILN: ".$sale->shipping_iln;
$newId = $new->save(true);
//update E5 number in Twinpol

View File

@@ -1,5 +1,5 @@
<?php
// created: 2025-03-31 14:19:04
// created: 2025-04-10 09:38:48
$customDoms = array (
'ecmproducts_attribute_dom' =>
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 (

View File

@@ -1,5 +1,5 @@
<?php
// created: 2025-03-31 14:19:04
// created: 2025-04-10 09:38:48
$customDoms = array (
'ecmproducts_attribute_dom' =>
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 (

View File

@@ -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;

View File

@@ -55,7 +55,8 @@ if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
// SHOULD INCLUDE SELECTIVELY
class EcmProduct extends SugarBean {
class EcmProduct extends SugarBean
{
var $field_name_map = array();
// STANDARD FIELDS
var $id;
@@ -162,11 +163,8 @@ class EcmProduct extends SugarBean {
var $status;
var $add_status;
var $models;
var $position_list;
var $th;
var $url1;
var $url2;
var $url3;
@@ -176,6 +174,7 @@ class EcmProduct extends SugarBean {
var $url7;
var $url8;
var $url9;
var $ean;
// RELATED FIELDS
var $created_by;
@@ -194,34 +193,36 @@ class EcmProduct extends SugarBean {
// USED TO RETRIEVE RELATED FIELDS FROM FORM POSTS.
var $additional_column_fields = Array(
var $additional_column_fields = array(
'assigned_user_name',
'assigned_user_id',
'modified_user_id',
'created_by',
);
var $relationship_fields = Array(
var $relationship_fields = array(
//RELATIONSHIP FIELDS
);
function EcmProduct() {
function EcmProduct()
{
parent::SugarBean();
$this->setupCustomFields('EcmProducts');
foreach ($this->field_defs as $field)
{
foreach ($this->field_defs as $field) {
$this->field_name_map[$field['name']] = $field;
}
}
var $new_schema = true;
function get_summary_text(){
function get_summary_text()
{
return "$this->name";
}
function create_list_query($order_by, $where, $show_deleted = 0){
function create_list_query($order_by, $where, $show_deleted = 0)
{
// Fill in the assigned_user_name
$custom_join = $this->custom_fields->getJOIN();
$query = "SELECT ";
@@ -253,8 +254,7 @@ class EcmProduct extends SugarBean {
$query .= "where " . $where_auto;
if (substr_count($order_by, '.') > 0) {
$query .= " ORDER BY $order_by";
}
else if($order_by != "")
} else if ($order_by != "")
$query .= " ORDER BY $order_by";
else
$query .= " ORDER BY ecmproducts.name";
@@ -262,7 +262,8 @@ class EcmProduct extends SugarBean {
return $query;
}
function create_export_query($order_by, $where){
function create_export_query($order_by, $where)
{
$custom_join = $this->custom_fields->getJOIN();
$query = "SELECT
ecmproducts.*,
@@ -294,10 +295,10 @@ class EcmProduct extends SugarBean {
return $query;
}
function fill_in_additional_list_fields(){
}
function fill_in_additional_list_fields() {}
function fill_in_additional_detail_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);
@@ -319,7 +320,8 @@ class EcmProduct extends SugarBean {
//$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){
function getSale($date)
{
foreach ($date as $d) {
$z = "select
sum(
@@ -394,10 +396,10 @@ class EcmProduct extends SugarBean {
}
//echo $total_s." ".$total_p." ".$total_q."<br>";
return array("sale" => $total_s, "purchase" => $total_p, "quantity" => $total_q);
}
function get_list_view_data(){
function get_list_view_data()
{
global $current_language, $current_user;
global $numerek;
$numerek = $this->id;
@@ -416,7 +418,6 @@ class EcmProduct extends SugarBean {
//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'] = '<img src="pic.php?p=modules/EcmProducts/upload/images/' . $this->product_picture . '&w=90&h=84" border="0">';
}
$the_array['STOCK_QTY'] = 0;
$op = new EcmStockOperation();
@@ -434,12 +435,10 @@ class EcmProduct extends SugarBean {
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']) {
} 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="";
} else $st = "";
$this->retrieve($this->id);
@@ -517,8 +516,7 @@ class EcmProduct extends SugarBean {
if ($this->flag) {
$flag = 0;
$color = "red";
}
else {
} else {
$flag = 1;
$color = "#cccccc";
}
@@ -540,8 +538,9 @@ class EcmProduct extends SugarBean {
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();
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%'");
@@ -553,7 +552,8 @@ class EcmProduct extends SugarBean {
return $the_where;
}
function set_notification_body($xtpl, $simplemodule){
function set_notification_body($xtpl, $simplemodule)
{
global $mod_strings, $app_list_strings;
$xtpl->assign("NAME", $simplemodule->name);
@@ -561,19 +561,23 @@ class EcmProduct extends SugarBean {
return $xtpl;
}
function bean_implements($interface){
function bean_implements($interface)
{
switch ($interface) {
case 'ACL':return true;
case 'ACL':
return true;
}
return false;
}
function r($t){
function r($t)
{
$t = str_replace(".", "", $t);
$t = str_replace(",", ".", $t);
$t = floatval($t);
return $t;
}
function save($check_notify = FALSE){
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);
@@ -592,8 +596,7 @@ class EcmProduct extends SugarBean {
//echo $z;
$GLOBALS['db']->query($z);
header("Location: index.php?module=EcmProducts&action=index");
}
else{
} else {
$return_id = parent::save($check_notify);
//$components = self::ParseComponentsFromPOST();
@@ -611,7 +614,8 @@ class EcmProduct extends SugarBean {
}
static function ParseComponentsFromPOST() {
static function ParseComponentsFromPOST()
{
if (isset($_POST['position_list'])) {
$c_ = $_POST['position_list'];
$json = getJSONobj();
@@ -621,7 +625,8 @@ class EcmProduct extends SugarBean {
return false;
}
//***************************Start Managing Positions*************************//
function constructInsertQuery($data, $table = '') {
function constructInsertQuery($data, $table = '')
{
if ($table == '' && isset($this->object_name) && $this->object_name != '') {
$table = strtolower($this->object_name) . "components";
@@ -645,7 +650,8 @@ class EcmProduct extends SugarBean {
return $q;
}
function savePositions($id = null, $position_list = null) {
function savePositions($id = null, $position_list = null)
{
global $current_user, $timedate;
@@ -719,9 +725,9 @@ class EcmProduct extends SugarBean {
$this->db->query($this->constructInsertQuery($arr));
$position++;
}
}
function getPosition($position) {
function getPosition($position)
{
global $app_list_strings;
@@ -774,9 +780,9 @@ LIMIT 0,1
$return_array['ems_price'] = $c['purchase_price'];
return $return_array;
}
function getPositionList($array = false) {
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);
@@ -791,7 +797,8 @@ LIMIT 0,1
}
return $array ? false : '[]';
}
function deleteAssignedPositions() {
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);
@@ -801,7 +808,8 @@ LIMIT 0,1
}
//***************************End Managing Positions*************************//
//start managing categories
function savePositions3($pl) {
function savePositions3($pl)
{
global $current_user;
$exists = array();
@@ -828,7 +836,6 @@ LIMIT 0,1
$GLOBALS['db']->query($q);
$exists[] = $p['id'];
} else {
//insert new record
$id = create_guid();
@@ -853,7 +860,8 @@ LIMIT 0,1
$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) {
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'";
@@ -867,7 +875,6 @@ LIMIT 0,1
$w['ecmproductcategory_name'] = $n['name'];
$w['assigned_file'] = $n['assigned_file'];
$return_array[] = $w;
}
$json = getJSONobj();
@@ -877,7 +884,8 @@ LIMIT 0,1
return $array ? false : '[]';
}
function showPositions3(){
function showPositions3()
{
$arr = $this->getPositionList3(true);
@@ -917,7 +925,8 @@ LIMIT 0,1
//end managing categories
//prices manage
function savePrices($prices) {
function savePrices($prices)
{
if (!is_array($prices)) return null;
$fields = array('id', 'ecmprice_id', 'ecmproduct_id', 'price');
@@ -944,7 +953,8 @@ LIMIT 0,1
$db->query("delete from ecmprices_ecmproducts where ecmproduct_id='" . $this->id . "' AND id NOT IN ('" . implode("','", $new) . "')");
}
function getPricePosition($position) {
function getPricePosition($position)
{
if (!is_array($position)) return '';
global $timedate;
@@ -960,7 +970,8 @@ LIMIT 0,1
//var_dump($return_array);
return $return_array;
}
function getPricesList($array = false) {
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
@@ -983,7 +994,8 @@ LIMIT 0,1
return $array ? false : '[]';
}
function showPrices(){
function showPrices()
{
$arr = $this->getPricesList(true);
if (count($arr) > 0) {
$table = '
@@ -1008,7 +1020,8 @@ LIMIT 0,1
return $table;
}
//end manage prices
function getProductResInfo($product_id, $stock_id) {
function getProductResInfo($product_id, $stock_id)
{
$info = array();
global $db;
@@ -1043,7 +1056,8 @@ LIMIT 0,1
//search product by EAN
//simply try found product_id and executa function below
static function mobile_getProductInfoByEAN($params) {
static function mobile_getProductInfoByEAN($params)
{
$ean = trim($params['product_ean']);
if (!$ean || $ean == "")
return -2;
@@ -1065,14 +1079,16 @@ LIMIT 0,1
return EcmProduct::mobile_getProductInfo(
array(
'product_id' => $prod['id']
));
)
);
}
//ERROR CODES
// -2 - wrong paramaters
// -3 - can't find object
static function mobile_getProductInfo($params) {
static function mobile_getProductInfo($params)
{
$app_list_strings = return_app_list_strings_language("pl_pl");
$product_id = $params['product_id'];
@@ -1127,4 +1143,3 @@ LIMIT 0,1
return $result;
}
}
?>

View File

@@ -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;

View File

@@ -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<count($parr);$i++){