/** * Manxa Module - Tools * Sobreescriure la classe Tools per poder generar les crides al WebService de jRFC_Gateway * * @ver 1.0 * @author Manxa OIS * */ class Tools extends ToolsCore { /* * module: mxmodulefeag * date: 2020-11-27 08:58:39 * version: 1.0.0 */ public static function getPostjRFC_Gateway($SAPbapi, $prm) { $SAPgateway = Configuration::get('mxmodule_SAPGateway'); $SAPpool = Configuration::get('mxmodule_SAPPOOL'); $postdata = http_build_query( array( 'POOL' => $SAPpool, 'RFC' => $SAPbapi, 'params' => utf8_decode($prm) ) ); $opts = array('http' => array( 'method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => $postdata ) ); $context = stream_context_create($opts); return file_get_contents($SAPgateway.'gw', false, $context); } /* * module: mxmodulefeag * date: 2020-11-27 08:58:39 * version: 1.0.0 */ public static function getCustomerOrders($id_customer, $id_custumer_we, $rang = 1, $id_document='', $id_document_purchase='', $id_matnr='', $id_kdmat='', $id_status='') { $SAPvkorg = Configuration::get('mxmodule_SAPVKORG'); $SAPbapi = 'Z_HTML_SALESORDER_LIST2'; $spras = 'S'; //defecte Castellà if (!$cookie) { $cookie = Context::getContext()->cookie; } if (!$cookie->id_lang || !Validate::isUnsignedId($cookie->id_lang)) { $cookie->id_lang = (int)Configuration::get('PS_LANG_DEFAULT'); } $iso = Language::getIsoById((int)$cookie->id_lang); if ($iso == 'fr') $spras = 'F'; elseif ($iso == 'gb') $spras = 'E'; elseif ($iso == 'ca') $spras = 'c'; if ($rang > 36) $rang = 36; $f_fi = date('m/d/Y'); $f_in = date('m/d/Y', strtotime('-'.$rang.' month')); $id_customer = str_pad($id_customer, 10, '0', STR_PAD_LEFT); if ($id_custumer_we!=''){ $id_customer = str_pad($id_custumer_we, 10, '0', STR_PAD_LEFT); } $prm = '{"I_CUSTOMER_NUMBER": "'.$id_customer.'",'. '"I_SALES_ORGANIZATION":"FEAG",'. '"I_DOCUMENT_DATE": "'.$f_in.'",'. '"I_DOCUMENT_DATE_TO": "'.$f_fi.'",'. '"I_SPRAS":"'.$spras.'",'. '"I_MATERIAL":"'.$id_kdmat.'"}'; $jsonUrl = Tools::getPostjRFC_Gateway($SAPbapi, $prm); $jsonUrl = mb_convert_encoding($jsonUrl, 'UTF-8', mb_detect_encoding($jsonUrl, 'UTF-8, ISO-8859-1', true)); $data_temp = json_decode($jsonUrl, true); $data_real = null; $data_real['T_STATUS_DATA'] = array(); foreach ($data_temp['T_STATUS_DATA'] as $data_item){ $trobat = trobat; if ( $trobat && $id_status != ''){ $trobat = $id_status == $data_item['STATUS']; } if ( $trobat && $id_document_purchase != ''){ $trobat = $id_document_purchase == $data_item['VBELN'] || $id_document_purchase == $data_item['BSTNK']; } if ($trobat){ array_push($data_real['T_STATUS_DATA'], $data_item); } } return $data_real; } /* * module: mxmodulefeag * date: 2020-11-27 08:58:39 * version: 1.0.0 */ public static function getCustomerOffers($id_customer, $id_custumer_we, $rang = 1, $id_document='', $id_document_purchase='', $id_matnr='', $id_kdmat='', $id_status='') { $SAPvkorg = Configuration::get('mxmodule_SAPVKORG'); $SAPbapi = 'Z_HTML_QUOTATION_LIST'; if ($rang > 36) $rang = 36; $f_fi = date('m/d/Y'); $f_in = date('m/d/Y', strtotime('-'.$rang.' month')); $id_customer = str_pad($id_customer, 10, '0', STR_PAD_LEFT); if ($id_custumer_we > 0) $id_custumer_we = str_pad($id_custumer_we, 10, '0', STR_PAD_LEFT); else $id_custumer_we = ''; $prm = '{"I_KUNNR":"'.$id_customer.'",'. '"I_KUNWE":"'.$id_custumer_we.'",'. '"I_VKORG":"'.$SAPvkorg.'",'. '"I_DOCUMENT_DATE":"'.$f_in.'",'. '"I_DOCUMENT_DATE_TO":"'.$f_fi.'",'. '"I_KDMAT":"'.$id_kdmat.'"}'; $jsonUrl = Tools::getPostjRFC_Gateway($SAPbapi, $prm); $jsonUrl = mb_convert_encoding($jsonUrl, 'UTF-8', mb_detect_encoding($jsonUrl, 'UTF-8, ISO-8859-1', true)); $data_temp = json_decode($jsonUrl, true); $data_real = null; $data_real['T_STATUS_DATA'] = array(); foreach ($data_temp['T_STATUS_DATA'] as $data_item){ $trobat = true; if ( $trobat && $id_status != ''){ $trobat = ( ($id_status == 'AB' && $data_item['STATUS'] == 'A') || ($id_status == 'AB' && $data_item['STATUS'] == 'B') || ($id_status == 'CR' && $data_item['STATUS'] == 'C' && $data_item['SEMAFOR'] == 'R') || ($id_status == 'C' && $data_item['STATUS'] == 'C' && $data_item['SEMAFOR'] != 'R')); } if ( $trobat && $id_document_purchase != ''){ $trobat = $id_document_purchase == $data_item['VBELN'] || $id_document_purchase == $data_item['BSTNK']; } if ($trobat){ array_push($data_real['T_STATUS_DATA'], $data_item); } } $data_temp['T_STATUS_DATA'] = $data_real['T_STATUS_DATA']; return $data_temp; } /* * module: mxmodulefeag * date: 2020-11-27 08:58:39 * version: 1.0.0 */ public static function getCustomerOrderDetail($id_order) { $SAPbapi = 'Z_HTML_SALESORDER_DETAIL'; $prm = '{"T_SALES_DOCUMENTS":[{"VBELN":"'.str_pad($id_order, 10, '0', STR_PAD_LEFT).'"}]}'; $jsonUrl = Tools::getPostjRFC_Gateway($SAPbapi, $prm); $jsonUrl = mb_convert_encoding($jsonUrl, 'UTF-8', mb_detect_encoding($jsonUrl, 'UTF-8, ISO-8859-1', true)); return json_decode($jsonUrl, true); } /* * module: mxmodulefeag * date: 2020-11-27 08:58:39 * version: 1.0.0 */ public static function getCustomerSalesOrderPdf($id_customer, $path, $id_salesorder) { $SAPbapi = 'Z_HTML_SALESORDER_PDF'; $id_client = str_pad($id_customer, 10, '0', STR_PAD_LEFT); $prm = '{"I_VBELN":"'.$id_salesorder.'","I_CUSTOMER_NUMBER":"'.$id_client.'","I_SECURITY":"X"}'; $jsonUrl = Tools::getPostjRFC_Gateway($SAPbapi, $prm); $jsonUrl = mb_convert_encoding($jsonUrl, 'UTF-8', mb_detect_encoding($jsonUrl, 'UTF-8, ISO-8859-1', true)); $salesorder_data = json_decode($jsonUrl, true); try { $base64_string = $salesorder_data['I_BASE64']; $output_file = $path.$id_salesorder.'.pdf'; $ifp = fopen( $output_file, "wb" ); fwrite( $ifp, base64_decode( $base64_string) ); fclose( $ifp ); return $output_file; } catch (Exception $e) { return 'ERROR'; } } /* * module: mxmodulefeag * date: 2020-11-27 08:58:39 * version: 1.0.0 */ public static function getCustomerDeliverys($id_customer, $id_customer_we, $rang = 1, $id_document='') { $SAPvkorg = Configuration::get('mxmodule_SAPVKORG'); $SAPbapi = 'Z_HTML_DELIVERY_LIST'; if ($rang > 36) $rang = 36; $f_fi = date('m/d/Y'); $f_in = date('m/d/Y', strtotime('-'.$rang.' month')); $id_customer = str_pad($id_customer, 10, '0', STR_PAD_LEFT); if ($id_customer_we == 0) $id_customer_we = ''; else $id_customer_we = str_pad($id_customer_we, 10, '0', STR_PAD_LEFT); if ($id_document!=''){ $prm = '{"I_CUSTOMER_NUMBER":"'.$id_customer.'","I_SALES_ORGANIZATION":"'.$SAPvkorg.'","I_DOCUMENT_ID":"'.$id_document.'"}'; } else{ $prm = '{"I_CUSTOMER_NUMBER":"'.$id_customer.'","I_WE_NUMBER":"'.$id_customer_we.'","I_SALES_ORGANIZATION":"'.$SAPvkorg.'","I_DOCUMENT_DATE":"'.$f_in.'","I_DOCUMENT_DATE_TO":"'.$f_fi.'"}'; } $jsonUrl = Tools::getPostjRFC_Gateway($SAPbapi, $prm); $jsonUrl = mb_convert_encoding($jsonUrl, 'UTF-8', mb_detect_encoding($jsonUrl, 'UTF-8, ISO-8859-1', true)); return json_decode($jsonUrl, true); } /* * module: mxmodulefeag * date: 2020-11-27 08:58:39 * version: 1.0.0 */ public static function getCustomerDeliveryPdf($id_customer, $path, $id_delivery, $signed) { $id_client = str_pad($id_customer, 10, '0', STR_PAD_LEFT); if ($signed == 'X'){ $SAPbapi = 'Z_HTML_DELIVERY_PDF'; $prm = '{"I_VBELN":"'.$id_delivery.'","I_CUSTOMER_NUMBER":"'.$id_client.'","I_SECURITY":"X","I_SIGNED_APP":"'.$signed.'"}'; }else{ $SAPbapi = 'Z_HTML_PROFORMA_PDF'; $prm = '{"I_VBELN_LIKP":"'.$id_delivery.'","I_CUSTOMER_NUMBER":"'.$id_client.'","I_SECURITY":"X","I_VALORAT":"X" }'; } $jsonUrl = Tools::getPostjRFC_Gateway($SAPbapi, $prm); $jsonUrl = mb_convert_encoding($jsonUrl, 'UTF-8', mb_detect_encoding($jsonUrl, 'UTF-8, ISO-8859-1', true)); $delivery_data = json_decode($jsonUrl, true); try { $base64_string = $delivery_data['I_BASE64']; $output_file = $path.$id_delivery.'.pdf'; $ifp = fopen( $output_file, "wb" ); fwrite( $ifp, base64_decode( $base64_string) ); fclose( $ifp ); return $output_file; } catch (Exception $e) { return 'ERROR'; } } /* * module: mxmodulefeag * date: 2020-11-27 08:58:39 * version: 1.0.0 */ public static function getCustomerInvoices($id_customer, $rang = 1, $id_document='',$id_status='') { $SAPvkorg = Configuration::get('mxmodule_SAPVKORG'); $SAPbapi = 'Z_HTML_INVOICE_LIST'; if ($rang > 36) $rang = 36; $f_fi = date('m/d/Y'); $f_in = date('m/d/Y', strtotime('-'.$rang.' month')); $id_customer = str_pad($id_customer, 10, '0', STR_PAD_LEFT); $prm = '{"I_PARTNER_NUMBER":"'.$id_customer.'","I_SALES_ORGANIZATION_RES":"'.$SAPvkorg.'","I_DATE_FROM":"'.$f_in.'","I_DATE_TO":"'.$f_fi.'"}'; $jsonUrl = Tools::getPostjRFC_Gateway($SAPbapi, $prm); $jsonUrl = mb_convert_encoding($jsonUrl, 'UTF-8', mb_detect_encoding($jsonUrl, 'UTF-8, ISO-8859-1', true)); $data_temp = json_decode($jsonUrl, true); $data_real = null; $data_real['T_INVOICE_DATA'] = array(); foreach ($data_temp['T_INVOICE_DATA'] as $data_item){ $trobat = true; if ( $trobat && $id_status != ''){ $trobat = $id_status == $data_item['STATUS']; } if ( $trobat && $id_document != ''){ $trobat = $id_document == $data_item['BILLINGDOC']; } if ($trobat){ array_push($data_real['T_INVOICE_DATA'], $data_item); } } return $data_real; } /* * module: mxmodulefeag * date: 2020-11-27 08:58:39 * version: 1.0.0 */ public static function getCustomerInvoicePdf($id_customer, $path, $id_invoice) { $SAPbapi = 'Z_HTML_INVOICE_PDF'; $id_client = str_pad($id_customer, 10, '0', STR_PAD_LEFT); $prm = '{"I_VBELN":"'.$id_invoice.'","I_CUSTOMER_NUMBER":"'.$id_client.'","I_SECURITY":"X"}'; $jsonUrl = Tools::getPostjRFC_Gateway($SAPbapi, $prm); $jsonUrl = mb_convert_encoding($jsonUrl, 'UTF-8', mb_detect_encoding($jsonUrl, 'UTF-8, ISO-8859-1', true)); $invoice_data = json_decode($jsonUrl, true); try { $base64_string = $invoice_data['I_BASE64']; $output_file = $path.$id_invoice.'.pdf'; $ifp = fopen( $output_file, "wb" ); fwrite( $ifp, base64_decode( $base64_string) ); fclose( $ifp ); return $output_file; } catch (Exception $e) { return 'ERROR'; } } /* * module: mxmodulefeag * date: 2020-11-27 08:58:39 * version: 1.0.0 */ public static function getCustomerDelivery($id_customer) { $SAPvkorg = Configuration::get('mxmodule_SAPVKORG'); $SAPbapi = 'Z_HTML_KUNNR_WE'; $id_customer = str_pad($id_customer, 10, '0', STR_PAD_LEFT); $prm = '{"I_KUNNR":"'.$id_customer.'","I_VKORG":"'.$SAPvkorg.'"}'; $jsonUrl = Tools::getPostjRFC_Gateway($SAPbapi, $prm); $jsonUrl = mb_convert_encoding($jsonUrl, 'UTF-8', mb_detect_encoding($jsonUrl, 'UTF-8, ISO-8859-1', true)); return json_decode($jsonUrl, true); } /* * module: mxmodulefeag * date: 2020-11-27 08:58:39 * version: 1.0.0 */ public static function getCustomerVendor($id_customer) { $SAPvkorg = Configuration::get('mxmodule_SAPVKORG'); $SAPbapi = 'Z_HTML_KUNNR_VE'; $id_customer = str_pad($id_customer, 10, '0', STR_PAD_LEFT); $prm = '{"I_KUNNR":"'.$id_customer.'","I_VKORG":"'.$SAPvkorg.'", "I_HAS_EMAIL":"X"}'; $jsonUrl = Tools::getPostjRFC_Gateway($SAPbapi, $prm); $jsonUrl = mb_convert_encoding($jsonUrl, 'UTF-8', mb_detect_encoding($jsonUrl, 'UTF-8, ISO-8859-1', true)); return json_decode($jsonUrl, true); } /* * module: mxmodulefeag * date: 2020-11-27 08:58:39 * version: 1.0.0 */ public static function getCustomerVendorInfoDirectoriTelefonic($id_vendor) { $mysqli = new mysqli('localhost', 'directori', 'telefonic', 'acmi_directoritelefonic'); if ($mysqli->connect_errno) {exit;} $sql = "SELECT * FROM `usuari` WHERE agent = ".$id_vendor." LIMIT 1"; if (!$resultado = $mysqli->query($sql)) {exit;} $agent = $resultado->fetch_assoc(); $mysqli->close(); return $agent; } /* * module: mxmodulefeag * date: 2020-11-27 08:58:39 * version: 1.0.0 */ public static function setSalesOrderSimulate($id_customer, $id_customer_we, $items_in, $werk, $incoterms='ZPP') { $SAPvkorg = Configuration::get('mxmodule_SAPVKORG'); $SAPbapi = 'Z_HTML_SALESORDER_SIMULATE'; $id_customer = str_pad($id_customer, 10, '0', STR_PAD_LEFT); $id_customer_we = str_pad($id_customer_we, 10, '0', STR_PAD_LEFT); $header = '{"DOC_TYPE":"ZFEW","SALES_ORG":"'.$SAPvkorg.'","DIVISION":"GE","DISTR_CHAN":"GE","PURCH_NO_C":"TEST",'. '"INCOTERMS1":"'.$incoterms.'","CUST_GRP1":"290","CUST_GRP2":"290","LPRIO":"11"}'; $partners = '{"PARTN_NUMB":"'.$id_customer.'","PARTN_ROLE":"AG"},'.'{"PARTN_NUMB":"'.$id_customer_we.'","PARTN_ROLE":"WE"}'; $i = 1; $prm_items_or = ''; foreach ($items_in as $item) { $item_number = str_pad(''.($i*10), 6, '0', STR_PAD_LEFT); $item_matnr = str_pad($item['reference'], 18, '0', STR_PAD_LEFT); $item_qty = $item['quantity'].'000'; $item_umv = $item['mx_umv']; $prm_items_or = $prm_items_or.'{"ITM_NUMBER":"'.$item_number.'","MATERIAL":"'.$item_matnr.'","SALES_UNIT":"'.$item_umv.'","REQ_QTY":"'.$item_qty.'","PLANT":"'.$werk.'"}'; if ($i < count($items_in)){ $prm_items_or = $prm_items_or.','; } $i++; } $prm = '{'. '"S_ORDER_HEADER_IN":['.$header.'],'. '"T_ORDER_PARTNERS": ['.$partners.'],'. '"T_ORDER_ITEMS_IN": ['.$prm_items_or.']'. '}'; $jsonUrl = Tools::getPostjRFC_Gateway($SAPbapi, $prm); $jsonUrl = mb_convert_encoding($jsonUrl, 'UTF-8', mb_detect_encoding($jsonUrl, 'UTF-8, ISO-8859-1', true)); return json_decode($jsonUrl, true); } /* * module: mxmodulefeag * date: 2020-11-27 08:58:39 * version: 1.0.0 */ public static function setSalesOrderCreate($id_customer, $id_customer_we, $items_in, $ref_customer, $werk, $incoterms='ZPP', $hd_text) { $SAPvkorg = Configuration::get('mxmodule_SAPVKORG'); $SAPbapi = 'Z_HTML_SALESORDER_CREATE'; $id_customer = str_pad($id_customer, 10, '0', STR_PAD_LEFT); $id_customer_we = str_pad($id_customer_we, 10, '0', STR_PAD_LEFT); $header = '{"DOC_TYPE":"ZFEW","SALES_ORG":"'.$SAPvkorg.'","DIVISION":"GE","DISTR_CHAN":"GE","PURCH_NO_C":"'.$ref_customer.'",'. '"INCOTERMS1":"'.$incoterms.'","CUST_GRP1":"290","CUST_GRP2":"290","CUST_GRP4":"15","LPRIO":"11"}'; $partners = '{"PARTN_NUMB":"'.$id_customer.'","PARTN_ROLE":"AG"},'.'{"PARTN_NUMB":"'.$id_customer_we.'","PARTN_ROLE":"WE"}'; $i = 1; $prm_items_or = ''; $prm_items_sh = ''; foreach ($items_in as $item) { $item_number = $item['mx_simulate_itm']; $item_umv = $item['mx_umv']; $item_matnr = str_pad($item['reference'], 18, '0', STR_PAD_LEFT); $item_qty = $item['quantity']; $prm_items_or = $prm_items_or.'{"ITM_NUMBER":"'.$item_number.'","MATERIAL":"'.$item_matnr.'","SALES_UNIT":"'.$item_umv.'","PLANT":"'.$werk.'"}'; $prm_items_sh = $prm_items_sh.'{"ITM_NUMBER":"'.$item_number.'","REQ_QTY":"'.$item_qty.'","REQ_DATE":""}'; if ($i < count($items_in)){ $prm_items_or = $prm_items_or.','; $prm_items_sh = $prm_items_sh.','; } $i++; } $header_text = ''; if (isset($hd_text)){ $header_text = ',"T_ORDER_TEXT":[{"TEXT_ID":"0012","LANGU_ISO":"ES","FORMAT_COL":"10","TEXT_LINE":"'.$hd_text.'","ITM_NUMBER":""}]'; } $prm = '{'. '"S_ORDER_HEADER_IN": ['.$header.'],'. '"T_ORDER_PARTNERS": ['.$partners.'],'. '"T_ORDER_ITEMS_IN": ['.$prm_items_or.'],'. '"T_ORDER_SCHEDULES_IN":['.$prm_items_sh.']'.$header_text. '}'; $jsonUrl = Tools::getPostjRFC_Gateway($SAPbapi, $prm); $jsonUrl = mb_convert_encoding($jsonUrl, 'UTF-8', mb_detect_encoding($jsonUrl, 'UTF-8, ISO-8859-1', true)); return json_decode($jsonUrl, true); } /* * module: mxmodulefeag * date: 2020-11-27 08:58:39 * version: 1.0.0 */ public static function setQuotationCreate($id_customer, $id_customer_we, $items_in, $ref_customer, $werk, $incoterms='ZEP', $hd_text, $customer_email) { $SAPvkorg = Configuration::get('mxmodule_SAPVKORG'); $SAPbapi = 'Z_HTML_QUOTATION_CREATE'; $f_in = date('m/d/Y'); $f_fi = date('m/d/Y', strtotime('+1 month')); //Valida 1 mes vista $id_customer = str_pad($id_customer, 10, '0', STR_PAD_LEFT); $id_customer_we = str_pad($id_customer_we, 10, '0', STR_PAD_LEFT); $header = '{"DOC_TYPE":"ZAGG","SALES_ORG":"'.$SAPvkorg.'","PURCH_NO_C":"'.$ref_customer.'","REQ_DATE_H":"'.$f_in.'",'. '"INCOTERMS1":"'.$incoterms.'","DIVISION":"GE","DISTR_CHAN":"GE","CUST_GRP1":"290","CUST_GRP2":"290",'. '"QT_VALID_F":"'.$f_in.'","QT_VALID_T":"'.$f_fi.'","CUST_GRP4":"15","EMAIL_PSHP":"'.$customer_email.'"}'; $partners = '{"PARTN_NUMB":"'.$id_customer.'","PARTN_ROLE":"AG"},'.'{"PARTN_NUMB":"'.$id_customer_we.'","PARTN_ROLE":"WE"}'; $i = 1; $prm_items_or = ''; $prm_items_sh = ''; foreach ($items_in as $item) { $item_number = str_pad(''.($i*10), 6, '0', STR_PAD_LEFT); $item_matnr = str_pad($item['reference'], 18, '0', STR_PAD_LEFT); $item_umv = $item['mx_umv']; $item_qty = $item['quantity']; $prm_items_or = $prm_items_or.'{"ITM_NUMBER":"'.$item_number.'","MATERIAL":"'.$item_matnr. '","PLANT":"'.$werk.'","SALES_UNIT":"'.$item_umv.'","INCOTERMS1":"'.$incoterms.'","COND_TYPE":"PB00","COND_P_UNT":1}'; $prm_items_sh = $prm_items_sh.'{"ITM_NUMBER":"'.$item_number.'","REQ_QTY":"'.$item_qty.'","REQ_DATE":""}'; if ($i < count($items_in)){ $prm_items_or = $prm_items_or.','; $prm_items_sh = $prm_items_sh.','; } $i++; } $header_text = ''; if (isset($hd_text)){ $header_text = ',"T_QUOTATION_TEXT":[{"TEXT_ID":"0012","LANGU_ISO":"ES","FORMAT_COL":"10","TEXT_LINE":"'.$hd_text.'","ITM_NUMBER":""}]'; } $prm = '{'. '"S_QUOTATION_HEADER_IN": ['.$header.'],'. '"T_QUOTATION_PARTNERS": ['.$partners.'],'. '"T_QUOTATION_ITEMS_IN": ['.$prm_items_or.'],'. '"T_QUOTATION_SCHEDULES_IN":['.$prm_items_sh.']'.$header_text. '}'; $jsonUrl = Tools::getPostjRFC_Gateway($SAPbapi, $prm); $jsonUrl = mb_convert_encoding($jsonUrl, 'UTF-8', mb_detect_encoding($jsonUrl, 'UTF-8, ISO-8859-1', true)); return json_decode($jsonUrl, true); } /* * module: mxmodulefeag * date: 2020-11-27 08:58:39 * version: 1.0.0 */ public static function setSendMailConfig($id_customer, $id_customer_we, $items_in, $ref_customer, $werk, $incoterms='ZEP', $hd_text) { $SAPvkorg = Configuration::get('mxmodule_SAPVKORG'); $SAPbapi = 'Z_HTML_QUOTATION_CREATE'; $f_in = date('m/d/Y'); $f_fi = date('m/d/Y', strtotime('+1 month')); //Valida 1 mes vista $id_customer = str_pad($id_customer, 10, '0', STR_PAD_LEFT); $id_customer_we = str_pad($id_customer_we, 10, '0', STR_PAD_LEFT); $header = '{"DOC_TYPE":"ZAGG","SALES_ORG":"'.$SAPvkorg.'","PURCH_NO_C":"'.$ref_customer.'","REQ_DATE_H":"'.$f_in.'",'. '"INCOTERMS1":"'.$incoterms.'","DIVISION":"GE","DISTR_CHAN":"GE","CUST_GRP1":"290","CUST_GRP2":"290",'. '"QT_VALID_F":"'.$f_in.'","QT_VALID_T":"'.$f_fi.'"}'; $partners = '{"PARTN_NUMB":"'.$id_customer.'","PARTN_ROLE":"AG"},'.'{"PARTN_NUMB":"'.$id_customer_we.'","PARTN_ROLE":"WE"}'; $i = 1; $prm_items_or = ''; foreach ($items_in as $item) { $comma_separated = ''; $config_item = json_decode($item['mx_config']); $corte = 'Tipo Corte(recto)'; if ($config_item->{'tallrecte'} == '') $corte = 'Tipo Corte('.$config_item->{'tallbp'}.','.$config_item->{'tallbt'}.','.$config_item->{'tallbaa'}.','.$config_item->{'tallbab'}.'),'; $comma_separated = 'Marcaje('.$config_item->{'marcatge'}.'),'. 'Longitud('.$config_item->{'llargadamida'}.'mm),'. $corte. 'Agujeros('.$config_item->{'foratsn'}.','.$config_item->{'foratst'}.'),'. 'Granalla('.$config_item->{'granalla'}.'),'. 'Imprimación('.$config_item->{'impcolor'}.','.$config_item->{'impmida'}.')'; $prm_items_or = $prm_items_or.''.$i.'- (Material:'.$item['id_product'].'->'.$item['cart_quantity'].'UN),'.$comma_separated.',\n'; $i++; } $prm = '{'. '"S_QUOTATION_HEADER_IN": ['.$header.'],'. '"T_QUOTATION_PARTNERS": ['.$partners.'],'. '"I_PSHF_JSON_CONFIG":"'.$prm_items_or.'"'. '}'; $jsonUrl = Tools::getPostjRFC_Gateway($SAPbapi, $prm); $jsonUrl = mb_convert_encoding($jsonUrl, 'UTF-8', mb_detect_encoding($jsonUrl, 'UTF-8, ISO-8859-1', true)); return json_decode($jsonUrl, true); } /* * module: mxmodulefeag * date: 2020-11-27 08:58:39 * version: 1.0.0 */ public static function getInfoVendesClient($id_customer, $id_customer_we, $rang = 1, $id_kdmat ){ $SAPvkorg = Configuration::get('mxmodule_SAPVKORG'); $SAPbapi = 'Z_HTML_INFO_VENDES'; if ($rang > 36) $rang = 36; $f_fi = date('m/d/Y'); $f_in = date('m/d/Y', strtotime('-'.$rang.' month')); $id_customer = str_pad($id_customer, 10, '0', STR_PAD_LEFT); if ($id_customer_we == 0) $id_customer_we = ''; else $id_customer_we = str_pad($id_customer_we, 10, '0', STR_PAD_LEFT); $prm = '{"I_KUNNR": "'.$id_customer_we. '","I_KUNAG": "'.$id_customer. '","I_VKORG": "'.$SAPvkorg. '","I_DESDE": "'.$f_in. '","I_HASTA": "'.$f_fi.'"}'; $jsonUrl = Tools::getPostjRFC_Gateway($SAPbapi, $prm); $jsonUrl = mb_convert_encoding($jsonUrl, 'UTF-8', mb_detect_encoding($jsonUrl, 'UTF-8, ISO-8859-1', true)); $data_temp = json_decode($jsonUrl, true); $data_real = null; $data_real['T_ZHTML_VENDES'] = array(); foreach ($data_temp['T_ZHTML_VENDES'] as $data_item){ $trobat = true; if ( $trobat && $id_kdmat != ''){ $trobat = ($id_kdmat == $data_item['MATNR'] || $id_kdmat == $data_item['KDMAT']); } if ($trobat){ array_push($data_real['T_ZHTML_VENDES'], $data_item); } } return $data_real; } /* * module: mxmodulefeag * date: 2020-11-27 08:58:39 * version: 1.0.0 */ public static function getCertificats($id_customer, $id_customer_we, $rang = 1, $id_doc_customer, $id_kdmat){ $SAPvkorg = Configuration::get('mxmodule_SAPVKORG'); $SAPbapi = 'Z_HTML_CERTIFICATS_LIST'; if ($rang > 36) $rang = 36; $f_fi = date('m/d/Y'); $f_in = date('m/d/Y', strtotime('-'.$rang.' month')); $id_customer = str_pad($id_customer, 10, '0', STR_PAD_LEFT); if ($id_customer_we == 0) $id_customer_we = ''; else $id_customer_we = str_pad($id_customer_we, 10, '0', STR_PAD_LEFT); $prm = '{"I_KUNNR":"'.$id_customer. '","I_KUNWE":"'.$id_customer_we. '","I_VKORG":"'.$SAPvkorg. '","I_DOCUMENT_DATE":"'.$f_in. '","I_DOCUMENT_DATE_TO":"'.$f_fi.'"}'; $jsonUrl = Tools::getPostjRFC_Gateway($SAPbapi, $prm); $jsonUrl = mb_convert_encoding($jsonUrl, 'UTF-8', mb_detect_encoding($jsonUrl, 'UTF-8, ISO-8859-1', true)); $data_temp = json_decode($jsonUrl, true); $data_real = null; $data_real['T_DATA_DOCUMENT_ITEMS'] = array(); $data_real['T_CERTIFICAT_H'] = array(); foreach ($data_temp['T_DATA_DOCUMENT_ITEMS'] as $data_item){ $trobat = true; if ( $trobat && $id_kdmat != ''){ $trobat = ($id_kdmat == $data_item['MATNR'] || $id_kdmat == $data_item['KDMAT']); } if ( $trobat && $id_doc_customer != ''){ $trobat = ($id_doc_customer == $data_item['BSTKD'] || $id_doc_customer == $data_item['VBELN'] || $id_doc_customer == $data_item['BILLINGDOC']); } if ($trobat){ array_push($data_real['T_DATA_DOCUMENT_ITEMS'], $data_item); foreach ($data_temp['T_CERTIFICAT_H'] as $data_item_certificat){ if ($data_item_certificat['MATNR'] == $data_item['MATNR'] && $data_item_certificat['CHARG'] == $data_item['CHARG']){ array_push($data_real['T_CERTIFICAT_H'], $data_item_certificat); } } } } return $data_real; } /* * module: mxmodulefeag * date: 2020-11-27 08:58:39 * version: 1.0.0 */ public static function getCustomerCertificatePdf($archiv_id, $arc_doc_id, $path, $name) { $SAPbapi = 'Z_HTML_CERTIFICATS_PDF'; $prm = '{"I_ARCHIV_ID":"'.$archiv_id.'","I_ARC_DOC_ID":"'.$arc_doc_id.'"}'; $jsonUrl = Tools::getPostjRFC_Gateway($SAPbapi, $prm); $jsonUrl = mb_convert_encoding($jsonUrl, 'UTF-8', mb_detect_encoding($jsonUrl, 'UTF-8, ISO-8859-1', true)); $certificate_data = json_decode($jsonUrl, true); try { $base64_string = $certificate_data['I_BASE64']; $output_file = $path.$name.'.pdf'; $ifp = fopen( $output_file, "wb" ); fwrite( $ifp, base64_decode( $base64_string) ); fclose( $ifp ); return $output_file; } catch (Exception $e) { return 'ERROR'; } } /* * module: mxmodulefeag * date: 2020-11-27 08:58:39 * version: 1.0.0 */ public static function getCustomerCertificatePdfZip($id_customer, $id_customer_we, $rang = 1, $id_doc_customer, $id_kdmat, $path, $name) { $SAPvkorg = Configuration::get('mxmodule_SAPVKORG'); $SAPbapi = 'Z_HTML_CERTIFICATS_LIST'; if ($rang > 12) $rang = 12; $f_fi = date('m/d/Y'); $f_in = date('m/d/Y', strtotime('-'.$rang.' month')); $id_customer = str_pad($id_customer, 10, '0', STR_PAD_LEFT); if ($id_customer_we == 0) $id_customer_we = ''; else $id_customer_we = str_pad($id_customer_we, 10, '0', STR_PAD_LEFT); /*$id_type_s = 'LIKP'; //X Defecte Tipus entregua if ($id_type == 'f') $id_type_s = 'VBRK'; //Tipus factura*/ $prm = '{"I_KUNNR":"'.$id_customer. '","I_KUNWE":"'.$id_customer_we. '","I_VKORG":"'.$SAPvkorg. '","I_DOCUMENT_DATE":"'.$f_in. '","I_DOCUMENT_DATE_TO":"'.$f_fi. '","I_DO_ZIP":"X"}'; $jsonUrl = Tools::getPostjRFC_Gateway($SAPbapi, $prm); $jsonUrl = mb_convert_encoding($jsonUrl, 'UTF-8', mb_detect_encoding($jsonUrl, 'UTF-8, ISO-8859-1', true)); $certificate_data = json_decode($jsonUrl, true); try { $base64_string = $certificate_data['I_ZIPBASE64']; $output_file = $path.$name.'.zip'; $ifp = fopen( $output_file, "wb" ); fwrite( $ifp, base64_decode( $base64_string) ); fclose( $ifp ); return $output_file; } catch (Exception $e) { return 'ERROR'; } } /* * module: mxmodulefeag * date: 2020-11-27 08:58:39 * version: 1.0.0 */ public static function getProductsOrder($type, $value = null, $prefix = false) { /* FBS - 30/04/2018 - Sobreescrit el mètode per tal de sempre ordenar els productes amb mx_stock, així els filtres o llistats sempre aniran ordenats de la mateixa manera*/ switch ($type) { case 'by': /*$list = array(0 => 'name', 1 => 'price', 2 => 'date_add', 3 => 'date_upd', 4 => 'position', 5 => 'manufacturer_name', 6 => 'quantity', 7 => 'reference'); $value = (is_null($value) || $value === false || $value === '') ? (int)Configuration::get('PS_PRODUCTS_ORDER_BY') : $value; $value = (isset($list[$value])) ? $list[$value] : ((in_array($value, $list)) ? $value : 'position'); $order_by_prefix = ''; if ($prefix) { if ($value == 'id_product' || $value == 'date_add' || $value == 'date_upd' || $value == 'price') { $order_by_prefix = 'p.'; } elseif ($value == 'name') { $order_by_prefix = 'pl.'; } elseif ($value == 'manufacturer_name' && $prefix) { $order_by_prefix = 'm.'; $value = 'name'; } elseif ($value == 'position' || empty($value)) { $order_by_prefix = 'cp.'; } } return $order_by_prefix.$value;*/ return 'p.mx_stock'; break; case 'way': /*$value = (is_null($value) || $value === false || $value === '') ? (int)Configuration::get('PS_PRODUCTS_ORDER_WAY') : $value; $list = array(0 => 'asc', 1 => 'desc'); return ((isset($list[$value])) ? $list[$value] : ((in_array($value, $list)) ? $value : 'asc'));*/ return 'desc'; break; } } }