Download FV asDocument from E5 CRM; E-Commerce: fix rewizor encoding
This commit is contained in:
@@ -1,37 +1,38 @@
|
||||
<?php
|
||||
// preDb_0dcc87940d3655fa574b253df04ca1c3
|
||||
// %g7!@fG
|
||||
function createPzFromInvoice($record, $stockId) {
|
||||
function createPzFromInvoice($record, $stockId)
|
||||
{
|
||||
global $app_list_strings;
|
||||
$db = $GLOBALS['db'];
|
||||
|
||||
if ($stockId == null) {
|
||||
die('Nie wskazano magazynu');
|
||||
} else {
|
||||
$stock = $db->fetchByAssoc($db->query("SELECT id, name FROM ecmstocks WHERE id = '".$stockId."'"));
|
||||
$stock = $db->fetchByAssoc($db->query("SELECT id, name FROM ecmstocks WHERE id = '" . $stockId . "'"));
|
||||
if ($stock == null) {
|
||||
die("Wskazano błedny magazyn");
|
||||
}
|
||||
}
|
||||
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET' );
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
|
||||
curl_setopt($curl, CURLOPT_VERBOSE, 1);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
curl_setopt($curl, CURLOPT_URL, "https://crm.e5.pl/REST/index.php?key=7e50a8a5-f01f-4fbc-8c1b-59f3fc474bb5&action=getInvoice&record=".$record);
|
||||
curl_setopt($curl, CURLOPT_URL, "https://crm.e5.pl/REST/index.php?key=7e50a8a5-f01f-4fbc-8c1b-59f3fc474bb5&action=getInvoice&record=" . $record);
|
||||
$res = curl_exec($curl);
|
||||
$inv = json_decode($res);
|
||||
$inv->position_list = json_decode($inv->position_list);
|
||||
echo 'Tworzę dokument PZ w Twinpol<br>';
|
||||
echo 'Numer faktury: '.$inv->document_no.'<br>';
|
||||
echo 'Na magazyn: '.$stock['name'].' (ID: '.$stock['id'].')<br><br>';
|
||||
echo 'Numer faktury: ' . $inv->document_no . '<br>';
|
||||
echo 'Na magazyn: ' . $stock['name'] . ' (ID: ' . $stock['id'] . ')<br><br>';
|
||||
|
||||
//check if PZ not exists
|
||||
$exists = $db->fetchByAssoc($db->query("SELECT id, document_no FROM ecmstockdocins WHERE name='".$inv->document_no."'"));
|
||||
$exists = $db->fetchByAssoc($db->query("SELECT id, document_no FROM ecmstockdocins WHERE name='" . $inv->document_no . "'"));
|
||||
if ($exists) {
|
||||
echo "Istnieje już dokument PZ przypisany do tej faktury: <a target='new' href='https://crm.twinpol.com/index.php?module=EcmStockDocIns&action=DetailView&record=".$exists['id']."'>".$exists['document_no']."</a>";
|
||||
echo "Istnieje już dokument PZ przypisany do tej faktury: <a target='new' href='https://crm.twinpol.com/index.php?module=EcmStockDocIns&action=DetailView&record=" . $exists['id'] . "'>" . $exists['document_no'] . "</a>";
|
||||
die();
|
||||
}
|
||||
|
||||
@@ -74,14 +75,14 @@ function createPzFromInvoice($record, $stockId) {
|
||||
$pz->fromREST = true;
|
||||
|
||||
$gotAllProducts = true; // hope :)
|
||||
foreach ( $inv->position_list as $product ) {
|
||||
echo 'Produkt: '.$product->product_code.'<br>';
|
||||
foreach ($inv->position_list as $product) {
|
||||
echo 'Produkt: ' . $product->product_code . '<br>';
|
||||
$p = getProduct($product->product_code);
|
||||
if (!$p) {
|
||||
echo ' Produkt nie istnieje w bazie TWINPOL<br>';
|
||||
$gotAllProducts = false;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// add to pz
|
||||
$prod = array();
|
||||
$prod['date_entered'] = date('Y-m-d H:i:s');
|
||||
@@ -96,9 +97,9 @@ function createPzFromInvoice($record, $stockId) {
|
||||
$prod['product_code'] = $p->code;
|
||||
$prod['name'] = $p->name;
|
||||
$prod['quantity'] = $product->quantity;
|
||||
$prod['price'] = $product->price_netto;
|
||||
$prod['price_fk'] = $product->price_netto;
|
||||
$prod['total'] = $product->total_netto;
|
||||
$prod['price'] = $product->price_netto;
|
||||
$prod['price_fk'] = $product->price_netto;
|
||||
$prod['total'] = $product->total_netto;
|
||||
$prod['unit_id'] = $product->unit_id;
|
||||
$prod['unit_name'] = $product->unit_name;
|
||||
$prod['ecmproductcategory_id'] = $p->product_category_id;
|
||||
@@ -115,7 +116,7 @@ function createPzFromInvoice($record, $stockId) {
|
||||
die();
|
||||
} else {
|
||||
$new = $pz->save(true);
|
||||
echo '<a target="new" href="https://crm.twinpol.com/index.php?module=EcmStockDocIns&action=DetailView&record='.$new.'">Utworzono PZ.</a>';
|
||||
echo '<a target="new" href="https://crm.twinpol.com/index.php?module=EcmStockDocIns&action=DetailView&record=' . $new . '">Utworzono PZ.</a>';
|
||||
die();
|
||||
}
|
||||
}
|
||||
@@ -133,12 +134,13 @@ function sendStocks()
|
||||
}
|
||||
echo json_encode($stocks);
|
||||
}
|
||||
function sendSale($record) {
|
||||
function sendSale($record)
|
||||
{
|
||||
require_once('modules/EcmSales/EcmSale.php');
|
||||
$sale = new EcmSale();
|
||||
$sale->retrieve($record);
|
||||
$pl = $sale->getPositionList();
|
||||
$response = array (
|
||||
$response = array(
|
||||
'document_no' => $sale->document_no,
|
||||
'name' => $sale->name,
|
||||
'parent_document_no' => $sale->parent_document_no,
|
||||
@@ -167,15 +169,86 @@ function sendSale($record) {
|
||||
);
|
||||
echo json_encode($response);
|
||||
}
|
||||
|
||||
function updateSaleE5Number($record, $e5_record, $e5_document_no) {
|
||||
function updateSaleE5Number($record, $e5_record, $e5_document_no)
|
||||
{
|
||||
$db = $GLOBALS['db'];
|
||||
$db->query("UPDATE ecmsales SET edi_zs_id='$e5_record', edi_zs_document_no='$e5_document_no' WHERE id='$record'");
|
||||
die();
|
||||
}
|
||||
function createCostDocumentFromInvoice($record)
|
||||
{
|
||||
global $app_list_strings;
|
||||
$db = $GLOBALS['db'];
|
||||
|
||||
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');
|
||||
curl_setopt($curl, CURLOPT_VERBOSE, 1);
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
|
||||
curl_setopt($curl, CURLOPT_URL, "https://crm.e5.pl/REST/index.php?key=7e50a8a5-f01f-4fbc-8c1b-59f3fc474bb5&action=getInvoice&record=" . $record);
|
||||
$res = curl_exec($curl);
|
||||
$inv = json_decode($res);
|
||||
$inv->position_list = json_decode($inv->position_list);
|
||||
echo 'Tworzę dokument kosztowy w Twinpol<br>';
|
||||
echo 'Numer faktury: ' . $inv->document_no . '<br>';
|
||||
|
||||
removeDocumentIfExists($inv->document_no);
|
||||
|
||||
$doc = new Document();
|
||||
$doc->document_name = $inv->document_no;
|
||||
$doc->document_number = $inv->document_no;
|
||||
$doc->doc_symbol = $inv->document_no;
|
||||
$doc->revision = 1;
|
||||
|
||||
$doc->category_id = 'revision_note';
|
||||
$doc->status = '2';
|
||||
$doc->transaction_type = '1';
|
||||
$doc->document_type = 'k';
|
||||
|
||||
$doc->active_date = $inv->register_date;
|
||||
$doc->payment_date = $inv->payment_date;
|
||||
$doc->document_date = $inv->register_date;
|
||||
$doc->date_entered = date('Y-m-d H:i:s');
|
||||
$doc->date_modified = date('Y-m-d H:i:s');
|
||||
|
||||
$doc->value = $inv->total_brutto;
|
||||
$doc->left_paid = $inv->total_brutto;
|
||||
$doc->currency_id = $inv->currency_id;
|
||||
$doc->currency_value = 1;
|
||||
|
||||
$id = $doc->save();
|
||||
|
||||
$parents = array();
|
||||
$parent = array();
|
||||
$parent['id'] = create_guid();
|
||||
$parent['name'] = 'E5 Polska Sp. z o.o.';
|
||||
$parent['parent_id'] = 'f084e64a-4e63-a3d1-6417-58cbf730df3f';
|
||||
$parent['parent_type'] = 'Accounts';
|
||||
$parents[] = $parent;
|
||||
$doc->saveParentList($parents);
|
||||
|
||||
$vats = array();
|
||||
$vatList = explode(',', $inv->vats_summary);
|
||||
foreach ($vatList as $vatItem) {
|
||||
if (empty($vatItem)) continue;
|
||||
$parts = explode(':', $vatItem);
|
||||
if (count($parts) != 5) continue;
|
||||
$vat = array();
|
||||
$vat['netto'] = $parts[1];
|
||||
$vat['vat'] = $parts[2];
|
||||
$vat['vat_id'] = str_replace('%', '', $parts[0]);
|
||||
$vat['vat_value'] = $parts[0];
|
||||
$vats[] = $vat;
|
||||
}
|
||||
$doc->saveVatList($vats);
|
||||
|
||||
echo 'Utworzono dokument kosztowy: <a target="new" href="https://crm.twinpol.com/index.php?module=Documents&action=DetailView&record=' . $id . '">' . $doc->document_name . '</a><br>';
|
||||
}
|
||||
// local helpers
|
||||
function getProduct($code) {
|
||||
function getProduct($code)
|
||||
{
|
||||
$db = $GLOBALS['db'];
|
||||
$res = $db->fetchByAssoc($db->query("SELECT * FROM ecmproducts WHERE code='$code' AND deleted=0"));
|
||||
if (!$res) {
|
||||
@@ -187,6 +260,7 @@ function getProduct($code) {
|
||||
return $prod;
|
||||
}
|
||||
}
|
||||
/*
|
||||
function createProduct($record) {
|
||||
$curl = curl_init();
|
||||
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET' );
|
||||
@@ -221,11 +295,21 @@ function createProduct($record) {
|
||||
//$new->save();
|
||||
return $new;
|
||||
}
|
||||
function brecho($msg) {
|
||||
*/
|
||||
function removeDocumentIfExists($document_number)
|
||||
{
|
||||
$db = $GLOBALS['db'];
|
||||
$res = $db->fetchByAssoc($db->query("SELECT id FROM documents WHERE document_number='$document_number'"));
|
||||
if ($res) {
|
||||
echo 'Istnieje już dokument kosztowy o numerze ' . $document_number . '. Usuwam go...<br>';
|
||||
$db->query("DELETE FROM documents WHERE id='" . $res['id'] . "'");
|
||||
$db->query("DELETE FROM documents_accounts WHERE document_id='" . $res['id'] . "'");
|
||||
$db->query("DELETE FROM documents_vat WHERE document_id='" . $res['id'] . "'");
|
||||
}
|
||||
}
|
||||
function brecho($msg)
|
||||
{
|
||||
echo '<br><br>';
|
||||
var_dump($msg);
|
||||
echo '<br><br>';
|
||||
}
|
||||
|
||||
// mysql create table with fields id varchar, created_at datetime, and payload max text
|
||||
// create table e5_logs (id varchar(255), created_at datetime, payload text);
|
||||
|
||||
Reference in New Issue
Block a user