· 8 years ago · Jun 17, 2018, 07:56 AM
1<?php
2
3namespace tomal\connector;
4
5class Moy
6//class MySklad extends Connector
7{
8 private $idModule;
9 private $counterPartyTable;
10 private $assortmentTable;
11 private $currencyTable;
12 private $productTable;
13 private $serviceTable;
14 private $bundleTable;
15 private $productFolderTable;
16 private $variantTable;
17 private $consignmentTable;
18 private $contractTable;
19 private $projectTable;
20 private $expenseItemTable;
21 private $countriesTable;
22 private $groupsTable;
23 private $discountTable;
24 private $uomTable;
25 private $employeesTable;
26 private $storesTable;
27 private $organizationsTable;
28 private $accountsTable;
29 private $retailStoreTable;
30 private $cashiersTable;
31 private $taskTable;
32 private $retailshiftTable;
33 private $enterTable;
34 private $customerOrdersTable;
35 private $purchaseOrderTable;
36 private $invoiceOutTable;
37 private $invoiceInTable;
38 private $paymentInTable;
39 private $paymentOutTable;
40 private $cashInTable;
41 private $cashOutTable;
42 private $demandTable;
43 private $supplyTable;
44 private $lossTable;
45 private $moveTable;
46 private $retailDemandTable;
47 private $retailSalesReturnTable;
48 private $retailDrawerCashInTable;
49 private $retailDrawerCashOutTable;
50 private $salesReturnTable;
51 private $purchaseReturnTable;
52 private $factureOutTable;
53 private $factureInTable;
54 private $inventoryTable;
55 private $commissionReportInTable;
56 private $commissionReportOutTable;
57 private $pricelistTable;
58 private $processingPlanTable;
59 private $processingOrderTable;
60 private $processingTable;
61 private $internalOrderTable;
62 private $stockAllTable;
63 private $stockByStoreTable;
64 private $reportDashboardDayTable;
65 private $reportDashboardWeekTable;
66 private $reportDashboardMonthTable;
67 private $auditTable;
68 private $salePricesTable;
69 private $barcodesTable;
70 private $positionsInvoicesArrayTable;
71 private $positionsInvoicesTable;
72 private $positionsOrdersArrayTable;
73 private $positionsOrdersTable;
74 private $positionsDemandsArrayTable;
75 private $positionsDemandTable;
76 private $positionsSuppliesArrayTable;
77 private $positionsSupplyTable;
78 private $login;
79 private $username;
80 private $password;
81 private $limit;
82 private $project;
83
84
85 public function __construct($module, $login, $project, $username, $password)
86 {
87 error_reporting(E_ALL & ~E_NOTICE);
88
89 $this->idModule = $module;
90 $this->project = $project;
91 $this->counterPartyTable = "{$login}_{$project}_moy_sklad_counter_party";
92 $this->assortmentTable = "{$login}_{$project}_moy_sklad_assortment";
93 $this->currencyTable = "{$login}_{$project}_moy_sklad_currency";
94 $this->productTable = "{$login}_{$project}_moy_sklad_product";
95 $this->serviceTable = "{$login}_{$project}_moy_sklad_service";
96 $this->bundleTable = "{$login}_{$project}_moy_sklad_bundle";
97 $this->productFolderTable = "{$login}_{$project}_moy_sklad_productfolder";
98 $this->variantTable = "{$login}_{$project}_moy_sklad_variant";
99 $this->consignmentTable = "{$login}_{$project}_moy_sklad_consignment";
100 $this->contractTable = "{$login}_{$project}_moy_sklad_contract";
101 $this->projectTable = "{$login}_{$project}_moy_sklad_project";
102 $this->expenseItemTable = "{$login}_{$project}_moy_sklad_expense_item";
103 $this->countriesTable = "{$login}_{$project}_moy_sklad_countries";
104 $this->groupsTable = "{$login}_{$project}_moy_sklad_groups";
105 $this->discountTable = "{$login}_{$project}_moy_sklad_discount";
106 $this->uomTable = "{$login}_{$project}_moy_sklad_uom";
107 $this->employeesTable = "{$login}_{$project}_moy_sklad_employees";
108 $this->storesTable = "{$login}_{$project}_moy_sklad_stores";
109 $this->organizationsTable = "{$login}_{$project}_moy_sklad_organizations";
110 $this->accountsTable = "{$login}_{$project}_moy_sklad_accounts";
111 $this->retailStoreTable = "{$login}_{$project}_moy_sklad_retail_store";
112 $this->cashiersTable = "{$login}_{$project}_moy_sklad_cashiers";
113 $this->taskTable = "{$login}_{$project}_moy_sklad_task";
114 $this->retailshiftTable = "{$login}_{$project}_moy_sklad_retailshift";
115 $this->enterTable = "{$login}_{$project}_moy_sklad_enter";
116 $this->customerOrdersTable = "{$login}_{$project}_moy_sklad_customer_orders";
117 $this->purchaseOrderTable = "{$login}_{$project}_moy_sklad_customer_purchase_order";
118 $this->invoiceOutTable = "{$login}_{$project}_moy_sklad_invoice_out";
119 $this->invoiceInTable = "{$login}_{$project}_moy_sklad_invoice_in";
120 $this->paymentInTable = "{$login}_{$project}_moy_sklad_payment_in";
121 $this->paymentOutTable = "{$login}_{$project}_moy_sklad_payment_out";
122 $this->cashInTable = "{$login}_{$project}_moy_sklad_cash_in";
123 $this->cashOutTable = "{$login}_{$project}_moy_sklad_cash_out";
124 $this->demandTable = "{$login}_{$project}_moy_sklad_demand";
125 $this->supplyTable = "{$login}_{$project}_moy_entity_supply";
126 $this->lossTable = "{$login}_{$project}_moy_sklad_loss";
127 $this->moveTable = "{$login}_{$project}_moy_sklad_move";
128 $this->retailDemandTable = "{$login}_{$project}_moy_sklad_retail_demand";
129 $this->retailSalesReturnTable = "{$login}_{$project}_moy_sklad_retail_sales_return";
130 $this->retailDrawerCashInTable = "{$login}_{$project}_moy_sklad_retail_drawer_cash_in";
131 $this->retailDrawerCashOutTable = "{$login}_{$project}_moy_sklad_retail_drawer_cash_out";
132 $this->salesReturnTable = "{$login}_{$project}_moy_sklad_sales_return";
133 $this->purchaseReturnTable = "{$login}_{$project}_moy_sklad_purchase_return";
134 $this->factureOutTable = "{$login}_{$project}_moy_sklad_facture_out";
135 $this->factureOutTable = "{$login}_{$project}_moy_sklad_facture_in";
136 $this->inventoryTable = "{$login}_{$project}_moy_sklad_inventory";
137 $this->commissionReportInTable = "{$login}_{$project}_moy_sklad_commission_report_in";
138 $this->commissionReportInTable = "{$login}_{$project}_moy_sklad_commission_report_out";
139 $this->pricelistTable = "{$login}_{$project}_moy_sklad_pricelist";
140 $this->processingPlanTable = "{$login}_{$project}_moy_sklad_processing_plan";
141 $this->processingOrderTable = "{$login}_{$project}_moy_sklad_processing_order";
142 $this->processingTable = "{$login}_{$project}_moy_sklad_processing";
143 $this->internalOrderTable = "{$login}_{$project}_moy_sklad_internal_order";
144 $this->stockAllTable = "{$login}_{$project}_moy_sklad_stock_all";
145 $this->stockByStoreTable = "{$login}_{$project}_moy_sklad_stock_by_store";
146 $this->reportDashboardDayTable = "{$login}_{$project}_moy_sklad_report_dashboard_day";
147 $this->reportDashboardWeekTable = "{$login}_{$project}_moy_sklad_report_dashboard_week";
148 $this->reportDashboardMonthTable = "{$login}_{$project}_moy_sklad_report_dashboard_month";
149 $this->salePricesTable = "{$login}_{$project}_moy_sklad_sale_prices";
150 $this->barcodesTable = "{$login}_{$project}_moy_sklad_barcodes";
151 $this->auditTable = "{$login}_{$project}_moy_sklad_audit";
152 $this->positionsInvoicesArrayTable = "{$login}_{$project}_moy_sklad_positions_invoices_array";
153 $this->positionsInvoicesTable = "{$login}_{$project}_moy_sklad_positions_invoice";
154 $this->positionsOrdersArrayTable = "{$login}_{$project}_moy_sklad_positions_orders_array";
155 $this->positionsOrdersTable = "{$login}_{$project}_moy_sklad_positions_order";
156 $this->positionsDemandsArrayTable = "{$login}_{$project}_moy_sklad_positions_demands_array";
157 $this->positionsDemandTable = "{$login}_{$project}_moy_sklad_positions_demand";
158 $this->positionsSuppliesArrayTable = "{$login}_{$project}_moy_sklad_positions_supplies_array";
159 $this->positionsSupplyTable = "{$login}_{$project}_moy_sklad_positions_supply";
160 $this->login = $login;
161 $this->username = $username;
162 $this->password = $password;
163 $this->limit = 100;
164
165 if ($this->makeAuth()) {
166 $this->dropTable() && $this->createTable() && $this->init();
167 }
168
169 return true;
170 }
171
172 public function init()
173 {
174
175// $r =
176 $this->updateCounterPartyTable();
177 $this->updateAssortmentTable();
178 $this->updateCurrencyTable();
179 $this->updateProductTable();
180// $this->updateServiceTable();
181// $this->updateBundleTable();
182 $this->updateProductFolderTable();
183// $this->updateVariantTable();
184// $this->updateConsignmentTable();
185// $this->updateContractTable();
186 $this->updateProjectTable();
187 $this->updateExpenseItemTable();
188 $this->updateCountriesTable();
189 $this->updateGroupsTable();
190 $this->updateDiscountTable();
191 $this->updateUomTable();
192 $this->updateEmployeesTable();
193 $this->updateStoresTable();
194 $this->updateOrganizationsTable();
195// $this->updateRetailStoreTable();
196// $this->updateCashiersTable();
197// $this->updateTaskTable();
198// $this->updateRetailshiftTable();
199// $this->updateEnterTable();
200 $this->updateCustomerOrdersTable();
201 $this->updatePurchaseOrderTable();
202 $this->updateInvoiceOutTable();
203 $this->updateInvoiceInTable();
204 $this->updatePaymentInTable();
205 $this->updatePaymentOutTable();
206 $this->updateCashInTable();
207 $this->updateCashOutTable();
208 $this->updateDemandTable();
209 $this->updateSupplyTable();
210// $this->updateLossTable();
211// $this->updateMoveTable();
212// $this->updateRetaildemandTable();
213// $this->updateRetailsalesreturnTable();
214// $this->updateRetaildrawerCashInTable();
215// $this->updateRetaildrawerCashOutTable();
216// $this->updateSalesReturnTable();
217// $this->updatePurchasereturn();
218// $this->updateFactureout();
219// $this->updateFacturein();
220// $this->updateInventoryTable();
221// $this->updateCommissionreportin();
222// $this->updateCommissionreportout();
223// $this->updatePricelist();
224// $this->updateProcessingplan();
225// $this->updateProcessingOrderTable();
226// $this->updateProcessing();
227// $this->updateInternalorder();
228// $this->updateStockAllTable();
229// $this->updateStockBySort();
230// $this->updateReportDashboardDayTable();
231// $this->updateReportDashboardWeekTable();
232// $this->updateReportDashboardMonthTable();
233// $this->updateAuditTable();
234
235// var_dump($r);
236 }
237
238
239 private function updateCounterPartyTable()
240 {
241 $method = "entity/counterparty";
242 $dataDecoded = $this->getAllRows($method, 100);
243 if (!empty($dataDecoded)) {
244 foreach ($dataDecoded as $paginationItem) {
245 if (!empty($paginationItem)) {
246 foreach ($paginationItem as $row) {
247 $dataOwnerDecoded = json_decode($this->curlPost($row->owner->meta->href, $this->username, $this->password));
248 $dataStateDecoded = json_decode($this->curlPost($row->state->meta->href, $this->username, $this->password));
249
250 if (!empty($dataOwnerDecoded->id)) $ownerId = $dataOwnerDecoded->id; else $ownerId = null;
251 if (!empty($dataStateDecoded->stateType)) $stateType = $dataStateDecoded->stateType; else $stateType = null;
252 if (!empty($row->version)) $version = $row->version; else $version = null;
253 if (!empty($row->updated)) $updated = $row->updated; else $updated = null;
254 if (!empty($row->name)) $name = $row->name; else $name = null;
255 if (!empty($row->description)) $description = $row->description; else $description = null;
256 if (!empty($row->code)) $code = $row->code; else $code = null;
257 if (!empty($row->externalCode)) $externalCode = $row->externalCode; else $externalCode = null;
258 if (!empty($row->created)) $created = $row->created; else $created = null;
259 if (!empty($row->email)) $email = $row->email; else $email = null;
260 if (!empty($row->phone)) $phone = $row->phone; else $phone = null;
261 if (!empty($row->fax)) $fax = $row->fax; else $fax = null;
262 if (!empty($row->actualAddress)) $actualAddress = $row->actualAddress; else $actualAddress = null;
263 if (!empty($row->legalTitle)) $legalTitle = $row->legalTitle; else $legalTitle = null;
264 if (!empty($row->legalAddress)) $legalAddress = $row->legalAddress; else $legalAddress = null;
265 if (!empty($row->inn)) $inn = $row->inn; else $inn = null;
266 if (!empty($row->kpp)) $kpp = $row->kpp; else $kpp = null;
267 if (!empty($row->discountCardNumber)) $discountCardNumber = $row->discountCardNumber; else $discountCardNumber = null;
268 if (!empty($row->ogrn)) $ogrn = $row->ogrn; else $ogrn = null;
269 if (!empty($row->okpo)) $okpo = $row->okpo; else $okpo = null;
270 if (!empty($row->ogrnip)) $ogrnip = $row->ogrnip; else $ogrnip = null;
271 if (!empty($row->certificateNumber)) $certificateNumber = $row->certificateNumber; else $certificateNumber = null;
272 if (!empty($row->certificateDate)) $certificateDate = $row->certificateDate; else $certificateDate = null;
273 if (!empty($row->salesAmount)) $salesAmount = $row->salesAmount; else $salesAmount = null;
274 $archived = $this->checkIfArchived($row);
275 $shared = $this->checkIfShared($row);
276 $companyType = $this->getCompanyType($row);
277 $groupId = $this->getGroupId($row->group->meta->href);
278
279
280 $sql = "
281 INSERT INTO `{$this->counterPartyTable}` (`counter_party_id`, `owner_id`, `group_id`, `shared`, `version`, `updated`, `name`, `description`, `code`, `external_code`, `archived`, `created`, `email`, `phone`, `fax`, `actual_address`, `company_type`, `legal_title`, `legal_address`, `inn`, `kpp`, `ogrn`,`okpo`,`ogrnip`,`certificateNumber`, `certificateDate`, `discount_card_number`, `state_type`, `sales_amount`)
282 VALUES ('{$row->id}', '{$ownerId}', '{$groupId}', '{$shared}', '{$version}', '{$updated}', '{$name}', '{$description}', '{$code}', '{$externalCode}', '{$archived}', '{$created}', '{$email}', '{$phone}', '{$fax}', '{$actualAddress}', '{$companyType}', '{$legalTitle}', '{$legalAddress}', '{$inn}', '{$kpp}', '{$ogrn}', '{$okpo}', '{$ogrnip}', '{$certificateNumber}', '{$certificateDate}', '{$discountCardNumber}', '{$stateType}', '{$salesAmount}');
283 ";
284 $this->makeYiiOperation($sql);
285 }
286 }
287 }
288 return true;
289 }
290 return false;
291 }
292
293 private function updateAssortmentTable()
294 {
295 $method = "entity/assortment";
296 $dataDecoded = $this->getAllRows($method, 100);
297 if (!empty($dataDecoded)) {
298 foreach ($dataDecoded as $paginationItem) {
299 if (!empty($paginationItem)) {
300 foreach ($paginationItem as $row) {
301
302 $assortmentId = $row->id;
303 $dataOwnerDecoded = json_decode($this->curlPost($row->owner->meta->href, $this->username, $this->password));
304 $dataUomDecoded = json_decode($this->curlPost($row->uom->meta->href, $this->username, $this->password));
305 if (!empty($dataOwnerDecoded->id)) $ownerId = $dataOwnerDecoded->id; else $ownerId = null;
306 if (!empty($dataUomDecoded->id)) $uomId = $dataUomDecoded->id; else $uomId = null;
307 if (!empty($row->version)) $version = $row->version; else $version = null;
308 if (!empty($row->updated)) $updated = $row->updated; else $updated = null;
309 if (!empty($row->name)) $name = $row->name; else $name = null;
310 if (!empty($row->code)) $code = $row->code; else $code = null;
311 if (!empty($row->externalCode)) $externalCode = $row->externalCode; else $externalCode = null;
312 if (!empty($row->pathName)) $pathName = $row->pathName; else $pathName = null;
313 if (!empty($row->minPrice)) $minPrice = $row->minPrice; else $minPrice = null;
314 if (!empty($row->weight)) $weight = $row->weight; else $weight = null;
315 if (!empty($row->volume)) $volume = $row->volume; else $volume = null;
316 if (!empty($row->stock)) $stock = $row->stock; else $stock = null;
317 if (!empty($row->reserve)) $reserve = $row->reserve; else $reserve = null;
318 if (!empty($row->inTransit)) $inTransit = $row->inTransit; else $inTransit = null;
319 if (!empty($row->quantity)) $quantity = $row->quantity; else $quantity = null;
320
321 $archived = $this->checkIfArchived($row);
322 $shared = $this->checkIfShared($row);
323 if ($row->isSerialTrackable) $isSerialTrackable = "Да"; else $isSerialTrackable = "Ðет";
324 $groupId = $this->getGroupId($row->group->meta->href);
325
326
327 if (!empty($row->barcodes)) {
328 foreach ($row->salePrices as $salePrice) {
329 $dataCurrencyDecoded = json_decode($this->curlPost($salePrice->currency->meta->href, $this->username, $this->password));
330 $salePriceValue = $salePrice->value;
331 $salePriceCurrencyCode = $dataCurrencyDecoded->code;
332 $salePriceType = $salePrice->priceType;
333 $this->updateSalePricesTable($assortmentId, $salePriceValue, $salePriceCurrencyCode, $salePriceType);
334 }
335 }
336
337 if (!empty($row->barcodes)) {
338 foreach ($row->barcodes as $barcode) {
339 $this->updateBarcodesTable($assortmentId, $barcode);
340 }
341 }
342
343 $sql = "
344 INSERT INTO `{$this->assortmentTable}` (`assortment_id`, `owner_id`, `group_id`, `shared`, `version`, `updated`, `name`, `code`, `external_code`, `archived`, `path_name`, `uom_id`, `min_price`, `weight`, `volume`, `is_serial_trackable`, `stock`, `reserve`, `in_transit`, `quantity`)
345 VALUES ('{$assortmentId}', '{$ownerId}', '{$groupId}', '{$shared}', '{$version}', '{$updated}', '{$name}', '$code}', '{$externalCode}', '{$archived}', '{$pathName}', '{$uomId}', '{$minPrice}', '{$weight}', '{$volume}', '{$isSerialTrackable}', '{$stock}', '{$reserve}', '{$inTransit}', '{$quantity}');
346 ";
347
348 $this->makeYiiOperation($sql);
349
350 }
351 }
352 }
353 return true;
354 }
355 return false;
356 }
357
358 private function updateSalePricesTable($assortmentId, $salePriceValue, $salePriceCurrencyCode, $salePriceType)
359 {
360 $sql = "
361 INSERT INTO `{$this->salePricesTable}` (`assortment_id`, `value`, `currency_code`, `price_type`)
362 VALUES ('{$assortmentId}', '{$salePriceValue}', '{$salePriceCurrencyCode}', '{$salePriceType}');
363 ";
364 $this->makeYiiOperation($sql);
365
366 }
367
368 private function updateBarcodesTable($assortmentId, $barcode)
369 {
370 $sql = "
371 INSERT INTO `{$this->barcodesTable}` (`assortment_id`, `barcode`)
372 VALUES ('{$assortmentId}', '{$barcode}');
373 ";
374 $this->makeYiiOperation($sql);
375
376 }
377
378 private function updateCurrencyTable()
379 {
380 $method = "entity/currency";
381 $dataDecoded = $this->getAllRows($method, 100);
382
383 if (!empty($dataDecoded)) {
384 foreach ($dataDecoded as $paginationItem) {
385 if (!empty($paginationItem)) {
386 foreach ($paginationItem as $row) {
387 if (!empty($row->code)) $code = $row->code; else $code = null;
388 if (!empty($row->name)) $name = $row->name; else $name = null;
389 if (!empty($row->fullName)) $fullName = $row->fullName; else $fullName = null;
390 if (!empty($row->isoCode)) $isoCode = $row->isoCode; else $isoCode = null;
391
392 $sql = "
393 INSERT INTO `{$this->currencyTable}` (`code`, `name`, `full_name`, `iso_code`)
394 VALUES ('{$code}', '{$name}', '{$fullName}', '{$isoCode}');
395 ";
396 $this->makeYiiOperation($sql);
397
398 }
399 }
400 }
401 return true;
402 }
403 return false;
404 }
405
406 private function updateProductTable()
407 {
408 $method = "entity/product";
409 $dataDecoded = $this->getAllRows($method, 100);
410
411 if (!empty($dataDecoded)) {
412 foreach ($dataDecoded as $paginationItem) {
413 if (!empty($paginationItem)) {
414 foreach ($paginationItem as $row) {
415 $productId = $row->id;
416 $dataOwnerDecoded = json_decode($this->curlPost($row->owner->meta->href, $this->username, $this->password));
417 $dataUomDecoded = json_decode($this->curlPost($row->uom->meta->href, $this->username, $this->password));
418 if (!empty($dataOwnerDecoded->id)) $ownerId = $dataOwnerDecoded->id; else $ownerId = null;
419 if (!empty($dataUomDecoded->id)) $uomId = $dataUomDecoded->id; else $uomId = null;
420 if (!empty($row->version)) $version = $row->version; else $version = null;
421 if (!empty($row->updated)) $updated = $row->updated; else $updated = null;
422 if (!empty($row->name)) $name = $row->name; else $name = null;
423 if (!empty($row->description)) $description = $row->description; else $description = null;
424 if (!empty($row->code)) $code = $row->code; else $code = null;
425 if (!empty($row->externalCode)) $externalCode = $row->externalCode; else $externalCode = null;
426 if (!empty($row->pathName)) $pathName = $row->pathName; else $pathName = null;
427 if (!empty($row->vat)) $vat = $row->vat; else $vat = null;
428 if (!empty($row->effectiveVat)) $effectiveVat = $row->effectiveVat; else $effectiveVat = null;
429 if (!empty($row->minPrice)) $minPrice = $row->minPrice; else $minPrice = null;
430 if (!empty($row->buyPrice->value)) $buyPrice = $row->buyPrice->value; else $buyPrice = null;
431 if (!empty($row->modificationsCount)) $modificationsCount = $row->modificationsCount; else $modificationsCount = null;
432 if (!empty($row->minimumBalance)) $minimumBalance = $row->minimumBalance; else $minimumBalance = null;
433
434 $archived = $this->checkIfArchived($row);
435 $shared = $this->checkIfShared($row);
436 if ($row->isSerialTrackable) $isSerialTrackable = "Да"; else $isSerialTrackable = "Ðет";
437 $groupId = $this->getGroupId($row->group->meta->href);
438
439
440 if (!empty($row->barcodes)) {
441 foreach ($row->salePrices as $salePrice) {
442 $dataCurrencyDecoded = json_decode($this->curlPost($salePrice->currency->meta->href, $this->username, $this->password));
443 $salePriceValue = $salePrice->value;
444 $salePriceCurrencyCode = $dataCurrencyDecoded->code;
445 $salePriceType = $salePrice->priceType;
446 $this->updateSalePricesTable($productId, $salePriceValue, $salePriceCurrencyCode, $salePriceType);
447 }
448 }
449
450 if (!empty($row->barcodes)) {
451 foreach ($row->barcodes as $barcode) {
452 $this->updateBarcodesTable($productId, $barcode);
453 }
454 }
455
456 $sql = "
457 INSERT INTO `{$this->productTable}` (`product_id`, `owner_id`, `shared`, `group_id`, `version`, `updated`, `name`, `description`, `code`, `external_code`, `archived`, `path_name`, `vat`, `effective_vat`, `uom`, `min_price`, `buy_price`, `modifications_count`, `minimum_balance`, `is_serial_trackable`)
458 VALUES ('{$row->id}', '{$ownerId}', '{$shared}', '{$groupId}', '{$version}', '{$updated}', '{$name}', '{$description}', '{$code}', '{$externalCode}', '{$archived}', '{$pathName}', '{$vat}', '{$effectiveVat}', '{$uomId}', '{$minPrice}', '{$buyPrice}', '{$modificationsCount}', '{$minimumBalance}', '{$isSerialTrackable}');
459 ";
460 $this->makeYiiOperation($sql);
461
462 }
463 }
464 }
465 return true;
466 }
467 return false;
468 }
469
470 private function updateServiceTable()
471 {
472 $method = "entity/service";
473 $dataDecoded = $this->getAllRows($method, 100);
474 if (!empty($dataDecoded)) {
475 foreach ($dataDecoded as $paginationItem) {
476 if (!empty($paginationItem)) {
477 foreach ($paginationItem as $row) {
478 var_dump($row);
479 }
480 }
481 }
482 return true;
483 }
484 return false;
485 }
486
487 private function updateBundleTable()
488 {
489 $method = "entity/bundle";
490 $dataDecoded = $this->getAllRows($method, 100);
491 if (!empty($dataDecoded)) {
492 foreach ($dataDecoded as $paginationItem) {
493 if (!empty($paginationItem)) {
494 foreach ($paginationItem as $row) {
495 var_dump($row);
496 }
497 }
498 }
499 return true;
500 }
501 return false;
502 }
503
504 private function updateProductFolderTable()
505 {
506 $method = "entity/productfolder";
507 $dataDecoded = $this->getAllRows($method, 100);
508 if (!empty($dataDecoded)) {
509 foreach ($dataDecoded as $paginationItem) {
510 if (!empty($paginationItem)) {
511 foreach ($paginationItem as $row) {
512 $dataOwnerDecoded = json_decode($this->curlPost($row->owner->meta->href, $this->username, $this->password));
513 if (!empty($dataOwnerDecoded->id)) $ownerId = $dataOwnerDecoded->id; else $ownerId = null;
514 if (!empty($row->version)) $version = $row->version; else $version = null;
515 if (!empty($row->updated)) $updated = $row->updated; else $updated = null;
516 if (!empty($row->name)) $name = $row->name; else $name = null;
517 if (!empty($row->description)) $description = $row->description; else $description = null;
518 if (!empty($row->code)) $code = $row->code; else $code = null;
519 if (!empty($row->externalCode)) $externalCode = $row->externalCode; else $externalCode = null;
520 if (!empty($row->pathName)) $pathName = $row->pathName; else $pathName = null;
521 if (!empty($row->vat)) $vat = $row->vat; else $vat = null;
522 if (!empty($row->effectiveVat)) $effectiveVat = $row->effectiveVat; else $effectiveVat = null;
523 $shared = $this->checkIfShared($row);
524 $archived = $this->checkIfArchived($row);
525 $groupId = $this->getGroupId($row->group->meta->href);
526
527 $sql = "
528 INSERT INTO `{$this->productFolderTable}` (`product_folder_id`, `owner_id`, `shared`, `group_id`, `version`, `updated`, `name`, `description`, `code`, `external_code`, `archived`, `path_name`, `vat`, `effective_vat`)
529 VALUES ('{$row->id}', '{$ownerId}', '{$shared}', '{$groupId}', '{$version}', '{$updated}', '{$name}', '{$description}', '{$code}', '{$externalCode}', '{$archived}', '{$pathName}', '{$vat}', '{$effectiveVat}');
530 ";
531
532 $this->makeYiiOperation($sql);
533
534 if (!empty($row->productFolder)) {
535 $dataProductFolderDecoded = json_decode($this->curlPost($row->productFolder->meta->href, $this->username, $this->password));
536 $this->plusProductFolder($dataProductFolderDecoded);
537 }
538 }
539 }
540 }
541 return true;
542 }
543 return false;
544 }
545
546 private function plusProductFolder($row)
547 {
548 $dataOwnerDecoded = json_decode($this->curlPost($row->owner->meta->href, $this->username, $this->password));
549 if (!empty($dataOwnerDecoded->id)) $ownerId = $dataOwnerDecoded->id; else $ownerId = null;
550 if (!empty($row->version)) $version = $row->version; else $version = null;
551 if (!empty($row->updated)) $updated = $row->updated; else $updated = null;
552 if (!empty($row->name)) $name = $row->name; else $name = null;
553 if (!empty($row->description)) $description = $row->description; else $description = null;
554 if (!empty($row->code)) $code = $row->code; else $code = null;
555 if (!empty($row->externalCode)) $externalCode = $row->externalCode; else $externalCode = null;
556 if (!empty($row->pathName)) $pathName = $row->pathName; else $pathName = null;
557 if (!empty($row->vat)) $vat = $row->vat; else $vat = null;
558 if (!empty($row->effectiveVat)) $effectiveVat = $row->effectiveVat; else $effectiveVat = null;
559 $shared = $this->checkIfShared($row);
560 $archived = $this->checkIfArchived($row);
561 $groupId = $this->getGroupId($row->group->meta->href);
562
563 $sql = "
564 INSERT INTO `{$this->productFolderTable}` (`product_folder_id`, `owner_id`, `shared`, `group_id`, `version`, `updated`, `name`, `description`, `code`, `external_code`, `archived`, `path_name`, `vat`, `effective_vat`)
565 VALUES ('{$row->id}', '{$ownerId}', '{$shared}', '{$groupId}', '{$version}', '{$updated}', '{$name}', '{$description}', '{$code}', '{$externalCode}', '{$archived}', '{$pathName}', '{$vat}', '{$effectiveVat}');
566 ";
567 $this->makeYiiOperation($sql);
568
569
570 if (!empty($row->productFolder)) {
571 $dataProductFolderDecoded = json_decode($this->curlPost($row->productFolder->meta->href, $this->username, $this->password));
572 $this->plusProductFolder($dataProductFolderDecoded);
573 }
574 }
575
576 private function updateVariantTable()
577 {
578 $method = "entity/variant";
579 $dataDecoded = $this->getAllRows($method, 100);
580
581 if (!empty($dataDecoded)) {
582 foreach ($dataDecoded as $paginationItem) {
583 if (!empty($paginationItem)) {
584 foreach ($paginationItem as $row) {
585 var_dump($row);
586 }
587 }
588 }
589 return true;
590 }
591 return false;
592 }
593
594 private function updateConsignmentTable()
595 {
596 $method = "entity/consignment";
597 $dataDecoded = $this->getAllRows($method, 100);
598
599 if (!empty($dataDecoded)) {
600 foreach ($dataDecoded as $paginationItem) {
601 if (!empty($paginationItem)) {
602 foreach ($paginationItem as $row) {
603 var_dump($row);
604 }
605 }
606 }
607 return true;
608 }
609 return false;
610 }
611
612 private function updateContractTable()
613 {
614 $method = "entity/contract";
615 $dataDecoded = $this->getAllRows($method, 100);
616
617 if (!empty($dataDecoded)) {
618 foreach ($dataDecoded as $paginationItem) {
619 if (!empty($paginationItem)) {
620 foreach ($paginationItem as $row) {
621 var_dump($row);
622 }
623 }
624 }
625 return true;
626 }
627 return false;
628 }
629
630 private function updateProjectTable()
631 {
632 $method = "entity/project";
633 $dataDecoded = $this->getAllRows($method, 100);
634
635 if (!empty($dataDecoded)) {
636 foreach ($dataDecoded as $paginationItem) {
637 if (!empty($paginationItem)) {
638 foreach ($paginationItem as $row) {
639 $dataOwnerDecoded = json_decode($this->curlPost($row->owner->meta->href, $this->username, $this->password));
640
641 if (!empty($dataOwnerDecoded->id)) $ownerId = $dataOwnerDecoded->id; else $ownerId = null;
642 if (!empty($row->version)) $version = $row->version; else $version = null;
643 if (!empty($row->updated)) $updated = $row->updated; else $updated = null;
644 if (!empty($row->name)) $name = $row->name; else $name = null;
645 if (!empty($row->description)) $description = $row->description; else $description = null;
646 if (!empty($row->code)) $code = $row->code; else $code = null;
647 if (!empty($row->externalCode)) $externalCode = $row->externalCode; else $externalCode = null;
648
649 $archived = $this->checkIfArchived($row);
650 $shared = $this->checkIfShared($row);
651 $groupId = $this->getGroupId($row->group->meta->href);
652
653 $sql = "
654 INSERT INTO `{$this->projectTable}` (`project_id`, `owner_id`, `shared`, `group_id`, `version`, `updated`, `name`, `description`, `code`, `external_code`, `archived`)
655 VALUES ('{$row->id}', '{$ownerId}', '{$shared}', '{$groupId}', '{$version}', '{$updated}', '{$name}', '{$description}', '{$code}', '{$externalCode}', '{$archived}');
656 ";
657 $this->makeYiiOperation($sql);
658
659 }
660 }
661 }
662 return true;
663 }
664 return false;
665 }
666
667 private function updateExpenseItemTable()
668 {
669 $method = "entity/expenseitem";
670 $dataDecoded = $this->getAllRows($method, 100);
671
672 if (!empty($dataDecoded)) {
673 foreach ($dataDecoded as $paginationItem) {
674 if (!empty($paginationItem)) {
675 foreach ($paginationItem as $row) {
676
677 if (!empty($row->version)) $version = $row->version; else $version = null;
678 if (!empty($row->updated)) $updated = $row->updated; else $updated = null;
679 if (!empty($row->name)) $name = $row->name; else $name = null;
680 if (!empty($row->description)) $description = $row->description; else $description = null;
681 if (!empty($row->code)) $code = $row->code; else $code = null;
682 if (!empty($row->externalCode)) $externalCode = $row->externalCode; else $externalCode = null;
683
684 $sql = "
685 INSERT INTO `{$this->expenseItemTable}` (`expense_item_id`, `version`, `updated`, `name`, `description`, `code`, `external_code`)
686 VALUES ('{$row->id}', '{$version}', '{$updated}', '{$name}', '{$description}', '{$code}', '{$externalCode}');
687 ";
688 $this->makeYiiOperation($sql);
689
690 }
691 }
692 }
693 return true;
694 }
695 return false;
696 }
697
698 private function updateCountriesTable()
699 {
700 $method = "entity/country";
701 $dataDecoded = $this->getAllRows($method, 100);
702
703 if (!empty($dataDecoded)) {
704 foreach ($dataDecoded as $paginationItem) {
705 if (!empty($paginationItem)) {
706 foreach ($paginationItem as $row) {
707
708 $sql = "
709 INSERT INTO `{$this->countriesTable}` (`country_id`, `name`, `description`, `code`, `external_code`)
710 VALUES ('{$row->id}', '{$row->name}', '{$row->description}', '{$row->code}', '{$row->externalCode}');
711 ";
712 $this->makeYiiOperation($sql);
713
714 }
715 }
716 }
717 return true;
718 }
719 return false;
720 }
721
722 //
723 private function updateGroupsTable()
724 {
725 $method = "entity/group";
726 $dataDecoded = $this->getAllRows($method, 100);
727
728 if (!empty($dataDecoded)) {
729 foreach ($dataDecoded as $paginationItem) {
730 if (!empty($paginationItem)) {
731 foreach ($paginationItem as $row) {
732 $group_id = $this->getGroupId($row->meta->href);
733 $sql = "
734 INSERT INTO `{$this->groupsTable}` (`group_id`, `name`)
735 VALUES ('{$group_id}', '{$row->name}');
736 ";
737 $this->makeYiiOperation($sql);
738
739 }
740 }
741 }
742 return true;
743 }
744 return false;
745 }
746
747 private function updateDiscountTable()
748 {
749 $method = "entity/discount";
750 $dataDecoded = $this->getAllRows($method, 100);
751
752 if (!empty($dataDecoded)) {
753 foreach ($dataDecoded as $paginationItem) {
754 if (!empty($paginationItem)) {
755 foreach ($paginationItem as $row) {
756 var_dump($row);
757 }
758 }
759 }
760 return true;
761 }
762 return false;
763 }
764
765 private function updateUomTable()
766 {
767 $method = "entity/uom";
768 $dataDecoded = $this->getAllRows($method, 100);
769
770 if (!empty($dataDecoded)) {
771 foreach ($dataDecoded as $paginationItem) {
772 if (!empty($paginationItem)) {
773 foreach ($paginationItem as $row) {
774 $sql = "
775 INSERT INTO `{$this->uomTable}` (`uom_id`, `version`, `updated`, `name`,`description`, `code`, `external_code`)
776 VALUES ('{$row->id}', '{$row->version}', '{$row->updated}', '{$row->description}', '{$row->code}', '{$row->name}', '{$row->externalCode}');
777 ";
778
779 $this->makeYiiOperation($sql);
780
781 }
782 }
783 }
784 return true;
785 }
786 return false;
787 }
788
789 private function updateEmployeesTable()
790 {
791 $method = "entity/employee";
792 $dataDecoded = $this->getAllRows($method, 100);
793
794 if (!empty($dataDecoded)) {
795 foreach ($dataDecoded as $paginationItem) {
796 if (!empty($paginationItem)) {
797 foreach ($paginationItem as $row) {
798
799 $dataOwnerDecoded = json_decode($this->curlPost($row->owner->meta->href, $this->username, $this->password));
800 $dataRetailStoreDecoded = json_decode($this->curlPost($row->cashier->retailStore->meta->href, $this->username, $this->password));
801
802 if (!empty($dataOwnerDecoded->id)) $ownerId = $dataOwnerDecoded->id; else $ownerId = null;
803 if (!empty($row->cashier->id)) $cashierId = $row->cashier->id; else $cashierId = null;
804 if (!empty($dataRetailStoreDecoded->id)) $retailStoreId = $dataRetailStoreDecoded->id; else $retailStoreId = null;
805 if (!empty($row->version)) $version = $row->version; else $version = null;
806 if (!empty($row->updated)) $updated = $row->updated; else $updated = null;
807 if (!empty($row->externalCode)) $externalCode = $row->externalCode; else $externalCode = null;
808 if (!empty($row->created)) $created = $row->created; else $created = null;
809 if (!empty($row->uid)) $uid = $row->uid; else $uid = null;
810 if (!empty($row->email)) $email = $row->email; else $email = null;
811 if (!empty($row->phone)) $phone = $row->phone; else $phone = null;
812 if (!empty($row->fullName)) $fullName = $row->fullName; else $fullName = null;
813 if (!empty($row->shortFio)) $shortFio = $row->shortFio; else $shortFio = null;
814
815 $archived = $this->checkIfArchived($row);
816 $shared = $this->checkIfShared($row);
817 $groupId = $this->getGroupId($row->group->meta->href);
818
819 $sql = "
820 INSERT INTO `{$this->employeesTable}` (`employee_id`, `owner_id`, `group_id`, `shared`, `version`, `updated`, `external_code`, `archived`, `created`, `uid`, `email`, `phone`, `full_name`, `short_fio`, `cashier_id`, `retail_store_id`)
821 VALUES ('{$row->id}', '{$ownerId}', '{$groupId}', '{$shared}', '{$version}', '{$updated}', '{$externalCode}', '{$archived}', '{$created}', '{$uid}', '{$email}', '{$phone}', '{$fullName}', '{$shortFio}', '{$cashierId}', '{$retailStoreId}');
822 ";
823 $this->makeYiiOperation($sql);
824
825 }
826 }
827 }
828 return true;
829 }
830 return false;
831 }
832
833 //
834 private function updateStoresTable()
835 {
836 $method = "entity/store";
837 $dataDecoded = $this->getAllRows($method, 100);
838
839 if (!empty($dataDecoded)) {
840 foreach ($dataDecoded as $paginationItem) {
841 if (!empty($paginationItem)) {
842 foreach ($paginationItem as $row) {
843
844 $dataOwnerDecoded = json_decode($this->curlPost($row->owner->meta->href, $this->username, $this->password));
845 if (!empty($dataOwnerDecoded->id)) $ownerId = $dataOwnerDecoded->id; else $ownerId = null;
846 if (!empty($row->version)) $version = $row->version; else $version = null;
847 if (!empty($row->updated)) $updated = $row->updated; else $updated = null;
848 if (!empty($row->name)) $name = $row->name; else $name = null;
849 if (!empty($row->description)) $description = $row->description; else $description = null;
850 if (!empty($row->code)) $code = $row->code; else $code = null;
851 if (!empty($row->externalCode)) $externalCode = $row->externalCode; else $externalCode = null;
852 if (!empty($row->address)) $address = $row->address; else $address = null;
853 if (!empty($row->parent)) $parent = $row->parent; else $parent = null;
854 if (!empty($row->pathName)) $pathName = $row->pathName; else $pathName = null;
855 $archived = $this->checkIfArchived($row);
856 $shared = $this->checkIfShared($row);
857 $groupId = $this->getGroupId($row->group->meta->href);
858
859
860 $sql = "
861 INSERT INTO `{$this->storesTable}` (`store_id`, `owner_id`, `shared`, `group_id`, `version`, `updated`, `name`, `description`, `code`, `external_code`, `archived`, `address`, `parent`, `path_name`)
862 VALUES ('{$row->id}', '{$ownerId}', '{$shared}', '{$groupId}', '{$version}', '{$updated}', '{$name}', '{$description}', '{$code}', '{$externalCode}', '{$archived}', '{$address}', '{$parent}', '{$pathName}');
863 ";
864 $this->makeYiiOperation($sql);
865
866
867 }
868 }
869 }
870 return true;
871 }
872 return false;
873 }
874
875 private function updateOrganizationsTable()
876 {
877 $method = "entity/organization";
878 $dataDecoded = $this->getAllRows($method, 100);
879
880 if (!empty($dataDecoded)) {
881 foreach ($dataDecoded as $paginationItem) {
882 if (!empty($paginationItem)) {
883 foreach ($paginationItem as $row) {
884
885 $organizationId = $row->id;
886 $dataOwnerDecoded = json_decode($this->curlPost($row->owner->meta->href, $this->username, $this->password));
887 $dataAccountsDecoded = json_decode($this->curlPost($row->accounts->meta->href, $this->username, $this->password));
888 if (!empty($dataOwnerDecoded->id)) $ownerId = $dataOwnerDecoded->id; else $ownerId = null;
889 if (!empty($row->version)) $version = $row->version; else $version = null;
890 if (!empty($row->updated)) $updated = $row->updated; else $updated = null;
891 if (!empty($row->name)) $name = $row->name; else $name = null;
892 if (!empty($row->description)) $description = $row->description; else $description = null;
893 if (!empty($row->code)) $code = $row->code; else $code = null;
894 if (!empty($row->externalCode)) $externalCode = $row->externalCode; else $externalCode = null;
895 if (!empty($row->created)) $created = $row->created; else $created = null;
896 if (!empty($row->legalTitle)) $legalTitle = $row->legalTitle; else $legalTitle = null;
897 if (!empty($row->legalAddress)) $legalAddress = $row->legalAddress; else $legalAddress = null;
898 if (!empty($row->inn)) $inn = $row->inn; else $inn = null;
899 if (!empty($row->kpp)) $kpp = $row->kpp; else $kpp = null;
900 if (!empty($row->ogrn)) $ogrn = $row->ogrn; else $ogrn = null;
901 if (!empty($row->okpo)) $okpo = $row->okpo; else $okpo = null;
902 if (!empty($row->ogrnip)) $ogrnip = $row->ogrnip; else $ogrnip = null;
903 if (!empty($row->certificateNumber)) $certificateNumber = $row->certificateNumber; else $certificateNumber = null;
904 if (!empty($row->certificateDate)) $certificateDate = $row->certificateDate; else $certificateDate = null;
905 if (!empty($row->email)) $email = $row->email; else $email = null;
906 if (!empty($row->phone)) $phone = $row->phone; else $phone = null;
907 if (!empty($row->fax)) $fax = $row->fax; else $fax = null;
908 if (!empty($row->fsrarId)) $fsrarId = $row->fsrarId; else $fsrarId = null;
909 if (!empty($row->utmUrl)) $utmUrl = $row->utmUrl; else $utmUrl = null;
910 if (!empty($row->actualAddress)) $actualAddress = $row->actualAddress; else $actualAddress = null;
911 if (!empty($row->director)) $director = $row->director; else $director = null;
912 if (!empty($row->chiefAccountant)) $chiefAccountant = $row->chiefAccountant; else $chiefAccountant = null;
913
914 $archived = $this->checkIfArchived($row);
915 $shared = $this->checkIfShared($row);
916 $groupId = $this->getGroupId($row->group->meta->href);
917 $companyType = $this->getCompanyType($row);
918 $isEgaisEnable = $this->checkIfEgaisEnable($row);
919 $payerVat = $this->checkPayerVat($row);
920
921 $sql = "
922 INSERT INTO `{$this->organizationsTable}` (`organisation_id`, `owner_id`, `shared`, `group_id`, `version`, `updated`, `name`, `description`, `code`, `external_code`, `archived`, `created`, `company_type`, `legal_title`, `legal_address`, `inn`, `kpp`, `ogrn`, `ogrnip`, `okpo`, `certificate_number`, `certificate_date`, `email`, `phone`, `fax`, `is_egais_enable`, `fsrar_id`, `payer_vat`, `utm_url`, `actual_address`, `director`, `chief_accountant`)
923 VALUES ('{$organizationId}', '{$ownerId}', '{$shared}', '{$groupId}', '{$version}', '{$updated}', '{$name}', '{$description}', '{$code}', '{$externalCode}', '{$archived}', '{$created}', '{$companyType}', '{$legalTitle}', '{$legalAddress}', '{$inn}', '{$kpp}', '{$ogrn}', '{$ogrnip}', '{$okpo}', '{$certificateNumber}', '{$certificateDate}', '{$email}', '{$phone}', '{$fax}', '{$isEgaisEnable}', '{$fsrarId}', '{$payerVat}', '{$utmUrl}', '{$actualAddress}', '{$director}', '{$chiefAccountant}');
924 ";
925
926 $this->updateAccountsTable($organizationId, $dataAccountsDecoded);
927 $this->makeYiiOperation($sql);
928
929 }
930 }
931 }
932 return true;
933 }
934 return false;
935 }
936
937
938 private function updateAccountsTable($organizationId, $dataAccountsDecoded)
939 {
940
941 $dataAgencyDecoded = json_decode($this->curlPost($dataAccountsDecoded->agent->meta->href, $this->username, $this->password));
942 if (!empty($dataAgencyDecoded->id)) $agencyId = $dataAgencyDecoded->id; else $agencyId = null;
943
944 if (!empty($dataAccountsDecoded->version)) $version = $dataAccountsDecoded->version; else $version = null;
945 if (!empty($dataAccountsDecoded->updated)) $updated = $dataAccountsDecoded->updated; else $updated = null;
946 if (!empty($dataAccountsDecoded->accountNumber)) $accountNumber = $dataAccountsDecoded->accountNumber; else $accountNumber = null;
947 if (!empty($dataAccountsDecoded->bankName)) $bankName = $dataAccountsDecoded->bankName; else $bankName = null;
948 if (!empty($dataAccountsDecoded->bankLocation)) $bankLocation = $dataAccountsDecoded->bankLocation; else $bankLocation = null;
949 if (!empty($dataAccountsDecoded->correspondentAccount)) $correspondentAccount = $dataAccountsDecoded->correspondentAccount; else $correspondentAccount = null;
950 if (!empty($dataAccountsDecoded->bic)) $bic = $dataAccountsDecoded->bic; else $bic = null;
951 $isDefault = $this->checkIsDefault($dataAccountsDecoded);
952
953 $sql = "
954 INSERT INTO `{$this->accountsTable}` (`account_id`, `organisation_id`, `version`, `updated`, `is_default`, `account_number`, `bank_name`, `bank_location`, `correspondent_account`, `bic`, `agent_id`)
955 VALUES ('{$dataAccountsDecoded->id}', '{$organizationId}', '{$version}', '{$updated}', '{$isDefault}', '{$accountNumber}', '{$bankName}', '{$bankLocation}', '{$correspondentAccount}', '{$bic}', '{$agencyId}');
956 ";
957
958 $this->makeYiiOperation($sql);
959
960 }
961
962 private function updateRetailStoreTable()
963 {
964 $method = "entity/retailstore";
965 $dataDecoded = $this->getAllRows($method, 100);
966
967 if (!empty($dataDecoded)) {
968 foreach ($dataDecoded as $paginationItem) {
969 if (!empty($paginationItem)) {
970 foreach ($paginationItem as $row) {
971 $dataOwnerDecoded = json_decode($this->curlPost($row->{'owner'}->{'meta'}->{'href'}, $this->username, $this->password));
972
973 $sql = "
974 INSERT INTO `{$this->retailStoreTable}` (`login`, `retail_store_id`, `updated`, `name`, `discount_max_percent`, `price_type`, `owner_name`, `owner_email`, `owner_phone`)
975 VALUES ('{$this->login}', '{$row->{'id'}}', '{$row->{'updated'}}', '{$row->{'name'}}', '{$row->{'discountMaxPercent'}}', '{$row->{'priceType'}}', '{$dataOwnerDecoded->{'name'}}', '{$dataOwnerDecoded->{'email'}}', '{$dataOwnerDecoded->{'phone'}}');
976 ";
977 $this->makeYiiOperation($sql);
978
979 }
980 }
981 }
982 return true;
983 }
984 return false;
985 }
986
987 private function updateCashiersTable()
988 {
989 $method = "entity/cashiers";
990 $dataDecoded = $this->getAllRows($method, 100);
991
992 if (!empty($dataDecoded)) {
993 foreach ($dataDecoded as $paginationItem) {
994 if (!empty($paginationItem)) {
995 foreach ($paginationItem as $row) {
996 var_dump($row);
997 }
998 }
999 }
1000 return true;
1001 }
1002 return false;
1003 }
1004
1005 private function updateTaskTable()
1006 {
1007 $method = "entity/task";
1008 $dataDecoded = $this->getAllRows($method, 100);
1009
1010 if (!empty($dataDecoded)) {
1011 foreach ($dataDecoded as $paginationItem) {
1012 if (!empty($paginationItem)) {
1013 foreach ($paginationItem as $row) {
1014 var_dump($row);
1015 }
1016 }
1017 }
1018 return true;
1019 }
1020 return false;
1021 }
1022
1023 private function updateRetailshiftTable()
1024 {
1025 $method = "entity/retailshift";
1026 $dataDecoded = $this->getAllRows($method, 100);
1027
1028 if (!empty($dataDecoded)) {
1029 foreach ($dataDecoded as $paginationItem) {
1030 if (!empty($paginationItem)) {
1031 foreach ($paginationItem as $row) {
1032 var_dump($row);
1033 }
1034 }
1035 }
1036 return true;
1037 }
1038 return false;
1039 }
1040
1041 private function updateEnterTable()
1042 {
1043 $method = "entity/enter";
1044 $dataDecoded = $this->getAllRows($method, 100);
1045
1046 if (!empty($dataDecoded)) {
1047 foreach ($dataDecoded as $paginationItem) {
1048 if (!empty($paginationItem)) {
1049 foreach ($paginationItem as $row) {
1050 var_dump($row);
1051 }
1052 }
1053 }
1054 return true;
1055 }
1056 return false;
1057 }
1058
1059
1060 private function updateCustomerOrdersTable()
1061 {
1062 $method = "entity/customerorder";
1063 $dataDecoded = $this->getAllRows($method, 100);
1064
1065 if (!empty($dataDecoded)) {
1066 foreach ($dataDecoded as $paginationItem) {
1067 if (!empty($paginationItem)) {
1068 foreach ($paginationItem as $row) {
1069
1070 $customerOrderId = $row->id;
1071 $dataAgencyDecoded = json_decode($this->curlPost($row->agent->meta->href, $this->username, $this->password));
1072 $dataRateDecoded = json_decode($this->curlPost($row->rate->currency->meta->href, $this->username, $this->password));
1073 $dataProject = json_decode($this->curlPost($row->project->meta->href, $this->username, $this->password));
1074 $dataOwnerDecoded = json_decode($this->curlPost($row->owner->meta->href, $this->username, $this->password));
1075 $dataStoreDecoded = json_decode($this->curlPost($row->store->meta->href, $this->username, $this->password));
1076 $dataOrganizationDecoded = json_decode($this->curlPost($row->organization->meta->href, $this->username, $this->password));
1077 if (!empty($dataOrganizationDecoded->id)) $organizationId = $dataOrganizationDecoded->id; else $organizationId = null;
1078 if (!empty($dataStoreDecoded->id)) $storeId = $dataStoreDecoded->id; else $storeId = null;
1079 if (!empty($dataRateDecoded->code)) $rateId = $dataRateDecoded->code; else $rateId = null;
1080 if (!empty($dataProject->id)) $projectId = $dataProject->id; else $projectId = null;
1081 if (!empty($dataAgencyDecoded->id)) $agencyId = $dataAgencyDecoded->id; else $agencyId = null;
1082 if (!empty($dataOwnerDecoded->id)) $ownerId = $dataOwnerDecoded->id; else $ownerId = null;
1083 if (!empty($row->version)) $version = $row->version; else $version = null;
1084 if (!empty($row->updated)) $updated = $row->updated; else $updated = null;
1085 if (!empty($row->deleted)) $deleted = $row->deleted; else $deleted = null;
1086 if (!empty($row->name)) $name = $row->name; else $name = null;
1087 if (!empty($row->sum)) $sum = $row->sum; else $sum = null;
1088 if (!empty($row->description)) $description = $row->description; else $description = null;
1089 if (!empty($row->externalCode)) $externalCode = $row->externalCode; else $externalCode = null;
1090 if (!empty($row->moment)) $moment = $row->moment; else $moment = null;
1091 if (!empty($row->created)) $created = $row->created; else $created = null;
1092 if (!empty($row->deliveryPlannedMoment)) $deliveryPlannedMoment = $row->deliveryPlannedMoment; else $deliveryPlannedMoment = null;
1093 if (!empty($row->payedSum)) $payedSum = $row->payedSum; else $payedSum = null;
1094 if (!empty($row->vatSum)) $vatSum = $row->vatSum; else $vatSum = null;
1095 if (!empty($row->reservedSum)) $reservedSum = $row->reservedSum; else $reservedSum = null;
1096 if (!empty($row->shippedSum)) $shippedSum = $row->shippedSum; else $shippedSum = null;
1097 if (!empty($row->invoicedSum)) $invoicedSum = $row->invoicedSum; else $invoicedSum = null;
1098
1099 $shared = $this->checkIfShared($row);
1100 $groupId = $this->getGroupId($row->group->meta->href);
1101 $applicable = $this->checkIfApplicable($row);
1102 $vatEnabled = $this->checkIfVatEnable($row);
1103
1104 $positionsHref = $row->positions->meta->href;
1105
1106 $this->updateOrdersPositionsArrayTable($customerOrderId, $positionsHref);
1107
1108 $sql = "
1109 INSERT INTO `{$this->customerOrdersTable}` (`customer_order_id`, `owner_id`, `version`, `updated`, `deleted`, `name`, `description`, `external_code`, `moment`, `applicable`, `vat_enabled`, `sum`, `rate`, `shared`, `group_id`, `organization_id`, `agent_id`, `store_id`, `created`, `vat_sum`, `reserved_sum`, `delivery_planned_moment`, `payed_sum`, `shipped_sum`, `invoiced_sum`, `project_id`)
1110 VALUES ('{$customerOrderId}', '{$ownerId}', '{$version}', '{$updated}', '{$deleted}', '{$name}', '{$description}', '{$externalCode}', '{$moment}', '{$applicable}', '{$vatEnabled}', '{$sum}', '{$rateId}', '{$shared}', '{$groupId}', '{$organizationId}', '{$agencyId}', '{$storeId}', '{$created}', '{$vatSum}', '{$reservedSum}', '{$deliveryPlannedMoment}', '{$payedSum}', '{$shippedSum}', '{$invoicedSum}', '{$projectId}');
1111 ";
1112 $this->makeYiiOperation($sql);
1113
1114 }
1115 }
1116 }
1117 return true;
1118 }
1119 return false;
1120 }
1121
1122
1123 private function updatePurchaseOrderTable()
1124 {
1125 $method = "entity/purchaseorder";
1126 $dataDecoded = $this->getAllRows($method, 100);
1127
1128 if (!empty($dataDecoded)) {
1129 foreach ($dataDecoded as $paginationItem) {
1130 if (!empty($paginationItem)) {
1131 foreach ($paginationItem as $row) {
1132 $purchaseOrderId = $row->id;
1133 $dataAgencyDecoded = json_decode($this->curlPost($row->agent->meta->href, $this->username, $this->password));
1134 $dataRateDecoded = json_decode($this->curlPost($row->rate->currency->meta->href, $this->username, $this->password));
1135 $dataProject = json_decode($this->curlPost($row->project->meta->href, $this->username, $this->password));
1136 $dataOwnerDecoded = json_decode($this->curlPost($row->owner->meta->href, $this->username, $this->password));
1137 $dataStoreDecoded = json_decode($this->curlPost($row->store->meta->href, $this->username, $this->password));
1138 $dataOrganizationDecoded = json_decode($this->curlPost($row->organization->meta->href, $this->username, $this->password));
1139 if (!empty($dataOrganizationDecoded->id)) $organizationId = $dataOrganizationDecoded->id; else $organizationId = null;
1140 if (!empty($dataStoreDecoded->id)) $storeId = $dataStoreDecoded->id; else $storeId = null;
1141 if (!empty($dataRateDecoded->code)) $rateId = $dataRateDecoded->code; else $rateId = null;
1142 if (!empty($dataProject->id)) $projectId = $dataProject->id; else $projectId = null;
1143 if (!empty($dataAgencyDecoded->id)) $agencyId = $dataAgencyDecoded->id; else $agencyId = null;
1144 if (!empty($dataOwnerDecoded->id)) $ownerId = $dataOwnerDecoded->id; else $ownerId = null;
1145 if (!empty($row->version)) $version = $row->version; else $version = null;
1146 if (!empty($row->updated)) $updated = $row->updated; else $updated = null;
1147 if (!empty($row->deleted)) $deleted = $row->deleted; else $deleted = null;
1148 if (!empty($row->name)) $name = $row->name; else $name = null;
1149 if (!empty($row->sum)) $sum = $row->sum; else $sum = null;
1150 if (!empty($row->description)) $description = $row->description; else $description = null;
1151 if (!empty($row->externalCode)) $externalCode = $row->externalCode; else $externalCode = null;
1152 if (!empty($row->moment)) $moment = $row->moment; else $moment = null;
1153 if (!empty($row->created)) $created = $row->created; else $created = null;
1154 if (!empty($row->deliveryPlannedMoment)) $deliveryPlannedMoment = $row->deliveryPlannedMoment; else $deliveryPlannedMoment = null;
1155 if (!empty($row->payedSum)) $payedSum = $row->payedSum; else $payedSum = null;
1156 if (!empty($row->vatSum)) $vatSum = $row->vatSum; else $vatSum = null;
1157 if (!empty($row->reservedSum)) $reservedSum = $row->reservedSum; else $reservedSum = null;
1158 if (!empty($row->shippedSum)) $shippedSum = $row->shippedSum; else $shippedSum = null;
1159 if (!empty($row->invoicedSum)) $invoicedSum = $row->invoicedSum; else $invoicedSum = null;
1160 if (!empty($row->waitSum)) $waitSum = $row->waitSum; else $waitSum = null;
1161
1162 $shared = $this->checkIfShared($row);
1163 $groupId = $this->getGroupId($row->group->meta->href);
1164 $applicable = $this->checkIfApplicable($row);
1165 $vatEnabled = $this->checkIfVatEnable($row);
1166
1167 $positionsHref = $row->positions->meta->href;
1168
1169 $this->updateOrdersPositionsArrayTable($purchaseOrderId, $positionsHref);
1170
1171 $sql = "
1172 INSERT INTO `{$this->purchaseOrderTable}` (`purchase_order_id`, `owner_id`, `version`, `updated`, `deleted`, `name`, `description`, `external_code`, `moment`, `applicable`, `vat_enabled`, `sum`, `rate`, `shared`, `group_id`, `organization_id`, `agent_id`, `store_id`, `created`, `vat_sum`, `reserved_sum`, `delivery_planned_moment`, `payed_sum`, `shipped_sum`, `invoiced_sum`, `project_id`, `wait_sum`)
1173 VALUES ('{$purchaseOrderId}', '{$ownerId}', '{$version}', '{$updated}', '{$deleted}', '{$name}', '{$description}', '{$externalCode}', '{$moment}', '{$applicable}', '{$vatEnabled}', '{$sum}', '{$rateId}', '{$shared}', '{$groupId}', '{$organizationId}', '{$agencyId}', '{$storeId}', '{$created}', '{$vatSum}', '{$reservedSum}', '{$deliveryPlannedMoment}', '{$payedSum}', '{$shippedSum}', '{$invoicedSum}', '{$projectId}', '{$waitSum}');
1174 ";
1175
1176 $this->makeYiiOperation($sql);
1177
1178 }
1179 }
1180 }
1181 return true;
1182 }
1183 return false;
1184 }
1185
1186 private function updateOrdersPositionsArrayTable($orderId, $positionsHref)
1187 {
1188 $dataDecoded = json_decode($this->curlPost($positionsHref, $this->username, $this->password));
1189 foreach ($dataDecoded as $paginationItem) {
1190 if (!empty($paginationItem)) {
1191 foreach ($dataDecoded->rows as $row) {
1192 $this->updateOrdersPositionsTable($row);
1193 $sql = "
1194 INSERT INTO `{$this->positionsOrdersArrayTable}` (`positions_array_id`, `position_id`)
1195 VALUES ('{$orderId}', '{$row->id}');
1196 ";
1197
1198 $this->makeYiiOperation($sql);
1199
1200 }
1201 }
1202 }
1203 return true;
1204 }
1205
1206
1207 private function updateOrdersPositionsTable($row)
1208 {
1209 $dataAssortmentDecoded = json_decode($this->curlPost($row->assortment->meta->href, $this->username, $this->password));
1210 if (!empty($row->quantity)) $quantity = $row->quantity; else $quantity = null;
1211 if (!empty($dataAssortmentDecoded->id)) $assortmentId = $dataAssortmentDecoded->id; else $assortmentId = null;
1212 if (!empty($row->price)) $price = $row->price; else $price = null;
1213 if (!empty($row->discount)) $discount = $row->discount; else $discount = null;
1214 if (!empty($row->vat)) $vat = $row->vat; else $vat = null;
1215 if (!empty($row->shipped)) $shipped = $row->shipped; else $shipped = null;
1216 if (!empty($row->reserve)) $reserve = $row->reserve; else $reserve = null;
1217 if (!empty($row->wait)) $wait = $row->wait; else $wait = null;
1218
1219 $sql = "
1220 INSERT INTO `{$this->positionsOrdersTable}` (`position_id`, `quantity`, `price`, `discount`, `vat`, `assortment_id`, `shipped`, `reserve`, `wait`)
1221 VALUES ('{$row->id}', '{$quantity}', '{$price}', '{$discount}', '{$vat}', '{$assortmentId}', '{$shipped}', '{$reserve}', '{$wait}');
1222 ";
1223 $this->makeYiiOperation($sql);
1224
1225 }
1226
1227 private function updateInvoiceOutTable()
1228 {
1229 $method = "entity/invoiceout";
1230 $dataDecoded = $this->getAllRows($method, 100);
1231
1232 if (!empty($dataDecoded)) {
1233 foreach ($dataDecoded as $paginationItem) {
1234 if (!empty($paginationItem)) {
1235 foreach ($paginationItem as $row) {
1236 $dataOwnerDecoded = json_decode($this->curlPost($row->owner->meta->href, $this->username, $this->password));
1237 $dataStoreDecoded = json_decode($this->curlPost($row->store->meta->href, $this->username, $this->password));
1238 $dataOrganizationDecoded = json_decode($this->curlPost($row->organization->meta->href, $this->username, $this->password));
1239 $dataAgencyDecoded = json_decode($this->curlPost($row->agent->meta->href, $this->username, $this->password));
1240 $dataRateDecoded = json_decode($this->curlPost($row->rate->currency->meta->href, $this->username, $this->password));
1241 $dataCustomerOrder = json_decode($this->curlPost($row->customerOrder->meta->href, $this->username, $this->password));
1242 $dataProject = json_decode($this->curlPost($row->project->meta->href, $this->username, $this->password));
1243
1244 if (!empty($dataAgencyDecoded->id)) $agencyId = $dataAgencyDecoded->id; else $agencyId = null;
1245 if (!empty($dataOrganizationDecoded->id)) $organizationId = $dataOrganizationDecoded->id; else $organizationId = null;
1246 if (!empty($dataOwnerDecoded->id)) $ownerId = $dataOwnerDecoded->id; else $ownerId = null;
1247 if (!empty($dataStoreDecoded->id)) $storeId = $dataStoreDecoded->id; else $storeId = null;
1248 if (!empty($dataCustomerOrder->id)) $customerOrderId = $dataCustomerOrder->id; else $customerOrderId = null;
1249 if (!empty($dataRateDecoded->code)) $rateId = $dataRateDecoded->code; else $rateId = null;
1250 if (!empty($dataProject->id)) $projectId = $dataProject->id; else $projectId = null;
1251 if (!empty($row->version)) $version = $row->version; else $version = null;
1252 if (!empty($row->updated)) $updated = $row->updated; else $updated = null;
1253 if (!empty($row->name)) $name = $row->name; else $name = null;
1254 if (!empty($row->externalCode)) $externalCode = $row->externalCode; else $externalCode = null;
1255 if (!empty($row->moment)) $moment = $row->moment; else $moment = null;
1256 if (!empty($row->sum)) $sum = $row->sum; else $sum = null;
1257 if (!empty($row->created)) $created = $row->created; else $created = null;
1258 if (!empty($row->vatSum)) $vatSum = $row->vatSum; else $vatSum = null;
1259 if (!empty($row->paymentPlannedMoment)) $paymentPlannedMoment = $row->paymentPlannedMoment; else $paymentPlannedMoment = null;
1260 if (!empty($row->payedSum)) $payedSum = $row->payedSum; else $payedSum = null;
1261 if (!empty($row->shippedSum)) $shippedSum = $row->shippedSum; else $shippedSum = null;
1262
1263 $shared = $this->checkIfShared($row->shared);
1264 $groupId = $this->getGroupId($row->group->meta->href);
1265 $applicable = $this->checkIfApplicable($row);
1266 $vatEnabled = $this->checkIfVatEnable($row);
1267 $positionsHref = $row->positions->meta->href;
1268
1269 $this->updateInvoicesPositionsArrayTable($row->id, $positionsHref);
1270
1271 $sql = "
1272 INSERT INTO `{$this->invoiceOutTable}` (`invoice_out_id`, `owner_id`, `shared`, `group_id`, `version`, `updated`, `name`, `external_code`, `moment`, `applicable`, `rate`, `sum`, `store_id`, `agent_id`, `organization_id`, `created`, `vat_enabled`, `vat_sum`, `payment_planned_moment`, `payed_sum`, `shipped_sum`, `project_id`, `customer_order_id`)
1273 VALUES ('{$row->id}', '{$ownerId}', '{$shared}', '{$groupId}', '{$version}', '{$updated}', '{$name}', '{$externalCode}', '{$moment}', '{$applicable}', '{$rateId}', '{$sum}', '{$storeId}', '{$agencyId}', '{$organizationId}', '{$created}', '{$vatEnabled}', '{$vatSum}', '{$paymentPlannedMoment}', '{$payedSum}', '{$shippedSum}', '{$projectId}', '{$customerOrderId}');
1274 ";
1275 $this->makeYiiOperation($sql);
1276
1277 }
1278 }
1279 }
1280 return true;
1281 }
1282 return false;
1283 }
1284
1285 private function updateInvoiceInTable()
1286 {
1287 $method = "entity/invoicein";
1288 $dataDecoded = $this->getAllRows($method, 100);
1289
1290 if (!empty($dataDecoded)) {
1291 foreach ($dataDecoded as $paginationItem) {
1292 if (!empty($paginationItem)) {
1293 foreach ($paginationItem as $row) {
1294
1295
1296 $dataOwnerDecoded = json_decode($this->curlPost($row->owner->meta->href, $this->username, $this->password));
1297 $dataStoreDecoded = json_decode($this->curlPost($row->store->meta->href, $this->username, $this->password));
1298 $dataOrganizationDecoded = json_decode($this->curlPost($row->organization->meta->href, $this->username, $this->password));
1299 $dataAgencyDecoded = json_decode($this->curlPost($row->agent->meta->href, $this->username, $this->password));
1300 $dataRateDecoded = json_decode($this->curlPost($row->rate->currency->meta->href, $this->username, $this->password));
1301 $dataProject = json_decode($this->curlPost($row->project->meta->href, $this->username, $this->password));
1302
1303 if (!empty($dataAgencyDecoded->id)) $agencyId = $dataAgencyDecoded->id; else $agencyId = null;
1304 if (!empty($dataOrganizationDecoded->id)) $organizationId = $dataOrganizationDecoded->id; else $organizationId = null;
1305 if (!empty($dataOwnerDecoded->id)) $ownerId = $dataOwnerDecoded->id; else $ownerId = null;
1306 if (!empty($dataStoreDecoded->id)) $storeId = $dataStoreDecoded->id; else $storeId = null;
1307 if (!empty($dataProject->id)) $projectId = $dataProject->id; else $projectId = null;
1308 if (!empty($row->version)) $version = $row->version; else $version = null;
1309 if (!empty($row->updated)) $updated = $row->updated; else $updated = null;
1310 if (!empty($row->name)) $name = $row->name; else $name = null;
1311 if (!empty($row->externalCode)) $externalCode = $row->externalCode; else $externalCode = null;
1312 if (!empty($row->moment)) $moment = $row->moment; else $moment = null;
1313 if (!empty($row->sum)) $sum = $row->sum; else $sum = null;
1314 if (!empty($dataRateDecoded->code)) $rateId = $dataRateDecoded->code; else $rateId = null;
1315 if (!empty($row->created)) $created = $row->created; else $created = null;
1316 if (!empty($row->vatSum)) $vatSum = $row->vatSum; else $vatSum = null;
1317 if (!empty($row->paymentPlannedMoment)) $paymentPlannedMoment = $row->paymentPlannedMoment; else $paymentPlannedMoment = null;
1318 if (!empty($row->payedSum)) $payedSum = $row->payedSum; else $payedSum = null;
1319 if (!empty($row->shippedSum)) $shippedSum = $row->shippedSum; else $shippedSum = null;
1320 if (!empty($row->incomingNumber)) $incomingNumber = $row->incomingNumber; else $incomingNumber = null;
1321 if (!empty($row->incomingDate)) $incomingDate = $row->incomingDate; else $incomingDate = null;
1322
1323 $shared = $this->checkIfShared($row->shared);
1324 $groupId = $this->getGroupId($row->group->meta->href);
1325 $applicable = $this->checkIfApplicable($row);
1326 $vatEnabled = $this->checkIfVatEnable($row);
1327 $positionsHref = $row->positions->meta->href;
1328
1329 $this->updateInvoicesPositionsArrayTable($row->id, $positionsHref);
1330
1331 $sql = "
1332 INSERT INTO `{$this->invoiceInTable}` (`invoice_in_id`, `owner_id`, `shared`, `group_id`, `version`, `updated`, `name`, `external_code`, `moment`, `applicable`, `rate`, `sum`, `store_id`, `agent_id`, `organization_id`, `created`, `vat_enabled`, `vat_sum`, `payment_planned_moment`, `payed_sum`, `shipped_sum`, `project_id`, `incoming_number`, `incoming_date` )
1333 VALUES ('{$row->id}', '{$ownerId}', '{$shared}', '{$groupId}', '{$version}', '{$updated}', '{$name}', '{$externalCode}', '{$moment}', '{$applicable}', '{$rateId}', '{$sum}', '{$storeId}', '{$agencyId}', '{$organizationId}', '{$created}', '{$vatEnabled}', '{$vatSum}', '{$paymentPlannedMoment}', '{$payedSum}', '{$shippedSum}', '{$projectId}', '{$incomingNumber}', '{$incomingDate}');
1334 ";
1335
1336
1337 $this->makeYiiOperation($sql);
1338
1339 }
1340 }
1341 }
1342 return true;
1343 }
1344 return false;
1345 }
1346
1347 private function updateInvoicesPositionsArrayTable($invoiceId, $positionsHref)
1348 {
1349 $dataDecoded = json_decode($this->curlPost($positionsHref, $this->username, $this->password));
1350 foreach ($dataDecoded as $paginationItem) {
1351 if (!empty($paginationItem)) {
1352 foreach ($dataDecoded->rows as $row) {
1353 $this->updateInvoicesPositionsTable($row);
1354 $sql = "
1355 INSERT INTO `{$this->positionsInvoicesArrayTable}` (`positions_array_id`, `position_id`)
1356 VALUES ('{$invoiceId}', '{$row->id}');
1357 ";
1358 $this->makeYiiOperation($sql);
1359
1360 }
1361 }
1362 }
1363 return true;
1364 }
1365
1366 private function updateInvoicesPositionsTable($row)
1367 {
1368 $dataAssortmentDecoded = json_decode($this->curlPost($row->assortment->meta->href, $this->username, $this->password));
1369 if (!empty($row->quantity)) $quantity = $row->quantity; else $quantity = null;
1370 if (!empty($dataAssortmentDecoded->id)) $assortmentId = $dataAssortmentDecoded->id; else $assortmentId = null;
1371 if (!empty($row->price)) $price = $row->price; else $price = null;
1372 if (!empty($row->discount)) $discount = $row->discount; else $discount = null;
1373 if (!empty($row->vat)) $vat = $row->vat; else $vat = null;
1374
1375 $sql = "
1376 INSERT INTO `{$this->positionsInvoicesTable}` (`position_id`, `quantity`, `price`, `discount`, `vat`, `assortment_id`)
1377 VALUES ('{$row->id}', '{$quantity}', '{$price}', '{$discount}', '{$vat}', '{$assortmentId}' );
1378 ";
1379
1380 $this->makeYiiOperation($sql);
1381
1382 }
1383
1384
1385 private function updatePaymentInTable()
1386 {
1387 $method = "entity/paymentin";
1388 $dataDecoded = $this->getAllRows($method, 100);
1389
1390 if (!empty($dataDecoded)) {
1391 foreach ($dataDecoded as $paginationItem) {
1392 if (!empty($paginationItem)) {
1393 foreach ($paginationItem as $row) {
1394
1395 $dataOwnerDecoded = json_decode($this->curlPost($row->owner->meta->href, $this->username, $this->password));
1396 $dataAgencyDecoded = json_decode($this->curlPost($row->agent->meta->href, $this->username, $this->password));
1397 $dataOrganizationDecoded = json_decode($this->curlPost($row->organization->meta->href, $this->username, $this->password));
1398 $dataRateDecoded = json_decode($this->curlPost($row->rate->currency->meta->href, $this->username, $this->password));
1399 if (!empty($dataOwnerDecoded->id)) $ownerId = $dataOwnerDecoded->id; else $ownerId = null;
1400 if (!empty($dataAgencyDecoded->id)) $agencyId = $dataAgencyDecoded->id; else $agencyId = null;
1401 if (!empty($dataOrganizationDecoded->id)) $organizationId = $dataOrganizationDecoded->id; else $organizationId = null;
1402 if (!empty($dataRateDecoded->code)) $rateId = $dataRateDecoded->code; else $rateId = null;
1403 if (!empty($row->version)) $version = $row->version; else $version = null;
1404 if (!empty($row->updated)) $updated = $row->updated; else $updated = null;
1405 if (!empty($row->deleted)) $deleted = $row->deleted; else $deleted = null;
1406 if (!empty($row->name)) $name = $row->name; else $name = null;
1407 if (!empty($row->description)) $description = $row->description; else $description = null;
1408 if (!empty($row->externalCode)) $externalCode = $row->externalCode; else $externalCode = null;
1409 if (!empty($row->moment)) $moment = $row->moment; else $moment = null;
1410 if (!empty($row->sum)) $sum = $row->sum; else $sum = null;
1411 if (!empty($row->created)) $created = $row->created; else $created = null;
1412 if (!empty($row->paymentPurpose)) $paymentPurpose = $row->paymentPurpose; else $paymentPurpose = null;
1413 if (!empty($row->vatSum)) $vatSum = $row->vatSum; else $vatSum = null;
1414 if (!empty($row->incomingDate)) $incomingDate = $row->incomingDate; else $incomingDate = null;
1415 if (!empty($row->incomingNumber)) $incomingNumber = $row->incomingNumber; else $incomingNumber = null;
1416 $groupId = $this->getGroupId($row->group->meta->href);
1417 $applicable = $this->checkIfApplicable($row);
1418 $shared = $this->checkIfShared($row);
1419
1420 $sql = "
1421 INSERT INTO `{$this->paymentInTable}` (`payment_in_id`, `version`, `updated`, `deleted`, `name`, `description`, `external_code`, `moment`, `applicable`, `sum`, `rate`, `owner_id`, `shared`, `group_id`, `organization_id`, `agent_id`, `created`, `payment_purpose`, `vat_sum`, `incoming_date`, `incoming_number`)
1422 VALUES ('{$row->id}', '{$version}', '{$updated}', '{$deleted}', '{$name}', '{$description}', '{$externalCode}', '{$moment}', '{$applicable}', '{$sum}', '{$rateId}', '{$ownerId}', '{$shared}', '{$groupId}', '{$organizationId}', '{$agencyId}', '{$created}', '{$paymentPurpose}', '{$vatSum}', '{$incomingDate}', '{$incomingNumber}');
1423 ";
1424 $this->makeYiiOperation($sql);
1425
1426 }
1427 }
1428 }
1429 return true;
1430 }
1431 return false;
1432 }
1433
1434 private function updatePaymentOutTable()
1435 {
1436 $method = "entity/paymentout";
1437 $dataDecoded = $this->getAllRows($method, 100);
1438
1439 if (!empty($dataDecoded)) {
1440 foreach ($dataDecoded as $paginationItem) {
1441 if (!empty($paginationItem)) {
1442 foreach ($paginationItem as $row) {
1443
1444 $dataOwnerDecoded = json_decode($this->curlPost($row->owner->meta->href, $this->username, $this->password));
1445 $dataAgencyDecoded = json_decode($this->curlPost($row->agent->meta->href, $this->username, $this->password));
1446 $dataOrganizationDecoded = json_decode($this->curlPost($row->organization->meta->href, $this->username, $this->password));
1447 $dataRateDecoded = json_decode($this->curlPost($row->rate->currency->meta->href, $this->username, $this->password));
1448 $dataExpenseItemDecoded = json_decode($this->curlPost($row->expenseItem->meta->href, $this->username, $this->password));
1449 if (!empty($dataOwnerDecoded->id)) $ownerId = $dataOwnerDecoded->id; else $ownerId = null;
1450 if (!empty($dataAgencyDecoded->id)) $agencyId = $dataAgencyDecoded->id; else $agencyId = null;
1451 if (!empty($dataOrganizationDecoded->id)) $organizationId = $dataOrganizationDecoded->id; else $organizationId = null;
1452 if (!empty($dataRateDecoded->code)) $rateId = $dataRateDecoded->code; else $rateId = null;
1453 if (!empty($dataExpenseItemDecoded->id)) $expenseItemId = $dataExpenseItemDecoded->id; else $expenseItemId = null;
1454 if (!empty($row->version)) $version = $row->version; else $version = null;
1455 if (!empty($row->updated)) $updated = $row->updated; else $updated = null;
1456 if (!empty($row->deleted)) $deleted = $row->deleted; else $deleted = null;
1457 if (!empty($row->name)) $name = $row->name; else $name = null;
1458 if (!empty($row->description)) $description = $row->description; else $description = null;
1459 if (!empty($row->externalCode)) $externalCode = $row->externalCode; else $externalCode = null;
1460 if (!empty($row->moment)) $moment = $row->moment; else $moment = null;
1461 if (!empty($row->sum)) $sum = $row->sum; else $sum = null;
1462 if (!empty($row->created)) $created = $row->created; else $created = null;
1463 if (!empty($row->paymentPurpose)) $paymentPurpose = $row->paymentPurpose; else $paymentPurpose = null;
1464 if (!empty($row->vatSum)) $vatSum = $row->vatSum; else $vatSum = null;
1465 $groupId = $this->getGroupId($row->group->meta->href);
1466 $applicable = $this->checkIfApplicable($row);
1467 $shared = $this->checkIfShared($row);
1468
1469 $sql = "
1470 INSERT INTO `{$this->paymentOutTable}` (`payment_in_id`, `version`, `updated`, `deleted`, `name`, `description`, `external_code`, `moment`, `applicable`, `sum`, `rate`, `owner_id`, `shared`, `group_id`, `organization_id`, `agent_id`, `created`, `payment_purpose`, `vat_sum`, `expense_item_id`)
1471 VALUES ('{$row->id}', '{$version}', '{$updated}', '{$deleted}', '{$name}', '{$description}', '{$externalCode}', '{$moment}', '{$applicable}', '{$sum}', '{$rateId}', '{$ownerId}', '{$shared}', '{$groupId}', '{$organizationId}', '{$agencyId}', '{$created}', '{$paymentPurpose}', '{$vatSum}', '{$expenseItemId}');
1472 ";
1473 $this->makeYiiOperation($sql);
1474
1475 }
1476 }
1477 }
1478 return true;
1479 }
1480 return false;
1481 }
1482
1483 private function updateCashInTable()
1484 {
1485 $method = "entity/cashin";
1486 $dataDecoded = $this->getAllRows($method, 100);
1487
1488 if (!empty($dataDecoded)) {
1489 foreach ($dataDecoded as $paginationItem) {
1490 if (!empty($paginationItem)) {
1491 foreach ($paginationItem as $row) {
1492
1493 $dataOwnerDecoded = json_decode($this->curlPost($row->owner->meta->href, $this->username, $this->password));
1494 $dataAgencyDecoded = json_decode($this->curlPost($row->agent->meta->href, $this->username, $this->password));
1495 $dataOrganizationDecoded = json_decode($this->curlPost($row->organization->meta->href, $this->username, $this->password));
1496 $dataRateDecoded = json_decode($this->curlPost($row->rate->currency->meta->href, $this->username, $this->password));
1497 if (!empty($dataOwnerDecoded->id)) $ownerId = $dataOwnerDecoded->id; else $ownerId = null;
1498 if (!empty($dataAgencyDecoded->id)) $agencyId = $dataAgencyDecoded->id; else $agencyId = null;
1499 if (!empty($dataOrganizationDecoded->id)) $organizationId = $dataOrganizationDecoded->id; else $organizationId = null;
1500 if (!empty($dataRateDecoded->code)) $rateId = $dataRateDecoded->code; else $rateId = null;
1501 if (!empty($row->version)) $version = $row->version; else $version = null;
1502 if (!empty($row->updated)) $updated = $row->updated; else $updated = null;
1503 if (!empty($row->deleted)) $deleted = $row->deleted; else $deleted = null;
1504 if (!empty($row->name)) $name = $row->name; else $name = null;
1505 if (!empty($row->description)) $description = $row->description; else $description = null;
1506 if (!empty($row->externalCode)) $externalCode = $row->externalCode; else $externalCode = null;
1507 if (!empty($row->moment)) $moment = $row->moment; else $moment = null;
1508 if (!empty($row->sum)) $sum = $row->sum; else $sum = null;
1509 if (!empty($row->created)) $created = $row->created; else $created = null;
1510 if (!empty($row->paymentPurpose)) $paymentPurpose = $row->paymentPurpose; else $paymentPurpose = null;
1511 if (!empty($row->vatSum)) $vatSum = $row->vatSum; else $vatSum = null;
1512 if (!empty($row->incomingDate)) $incomingDate = $row->incomingDate; else $incomingDate = null;
1513 if (!empty($row->incomingNumber)) $incomingNumber = $row->incomingNumber; else $incomingNumber = null;
1514 $groupId = $this->getGroupId($row->group->meta->href);
1515 $applicable = $this->checkIfApplicable($row);
1516 $shared = $this->checkIfShared($row);
1517
1518 $sql = "
1519 INSERT INTO `{$this->cashInTable}` (`payment_in_id`, `version`, `updated`, `deleted`, `name`, `description`, `external_code`, `moment`, `applicable`, `sum`, `rate`, `owner_id`, `shared`, `group_id`, `organization_id`, `agent_id`, `created`, `payment_purpose`, `vat_sum`, `incoming_date`, `incoming_number`)
1520 VALUES ('{$row->id}', '{$version}', '{$updated}', '{$deleted}', '{$name}', '{$description}', '{$externalCode}', '{$moment}', '{$applicable}', '{$sum}', '{$rateId}', '{$ownerId}', '{$shared}', '{$groupId}', '{$organizationId}', '{$agencyId}', '{$created}', '{$paymentPurpose}', '{$vatSum}', '{$incomingDate}', '{$incomingNumber}');
1521 ";
1522 $this->makeYiiOperation($sql);
1523
1524 }
1525 }
1526 }
1527 return true;
1528 }
1529 return false;
1530 }
1531
1532
1533 private function updateCashOutTable()
1534 {
1535 $method = "entity/cashout";
1536 $dataDecoded = $this->getAllRows($method, 100);
1537
1538 if (!empty($dataDecoded)) {
1539 foreach ($dataDecoded as $paginationItem) {
1540 if (!empty($paginationItem)) {
1541 foreach ($paginationItem as $row) {
1542
1543 $dataOwnerDecoded = json_decode($this->curlPost($row->owner->meta->href, $this->username, $this->password));
1544 $dataAgencyDecoded = json_decode($this->curlPost($row->agent->meta->href, $this->username, $this->password));
1545 $dataOrganizationDecoded = json_decode($this->curlPost($row->organization->meta->href, $this->username, $this->password));
1546 $dataRateDecoded = json_decode($this->curlPost($row->rate->currency->meta->href, $this->username, $this->password));
1547 $dataExpenseItemDecoded = json_decode($this->curlPost($row->expenseItem->meta->href, $this->username, $this->password));
1548 if (!empty($dataOwnerDecoded->id)) $ownerId = $dataOwnerDecoded->id; else $ownerId = null;
1549 if (!empty($dataAgencyDecoded->id)) $agencyId = $dataAgencyDecoded->id; else $agencyId = null;
1550 if (!empty($dataOrganizationDecoded->id)) $organizationId = $dataOrganizationDecoded->id; else $organizationId = null;
1551 if (!empty($dataRateDecoded->code)) $rateId = $dataRateDecoded->code; else $rateId = null;
1552 if (!empty($dataExpenseItemDecoded->id)) $expenseItemId = $dataExpenseItemDecoded->id; else $expenseItemId = null;
1553 if (!empty($row->version)) $version = $row->version; else $version = null;
1554 if (!empty($row->updated)) $updated = $row->updated; else $updated = null;
1555 if (!empty($row->deleted)) $deleted = $row->deleted; else $deleted = null;
1556 if (!empty($row->name)) $name = $row->name; else $name = null;
1557 if (!empty($row->description)) $description = $row->description; else $description = null;
1558 if (!empty($row->externalCode)) $externalCode = $row->externalCode; else $externalCode = null;
1559 if (!empty($row->moment)) $moment = $row->moment; else $moment = null;
1560 if (!empty($row->sum)) $sum = $row->sum; else $sum = null;
1561 if (!empty($row->created)) $created = $row->created; else $created = null;
1562 if (!empty($row->paymentPurpose)) $paymentPurpose = $row->paymentPurpose; else $paymentPurpose = null;
1563 if (!empty($row->vatSum)) $vatSum = $row->vatSum; else $vatSum = null;
1564 $groupId = $this->getGroupId($row->group->meta->href);
1565 $applicable = $this->checkIfApplicable($row);
1566 $shared = $this->checkIfShared($row);
1567
1568 $sql = "
1569 INSERT INTO `{$this->cashOutTable}` (`payment_in_id`, `version`, `updated`, `deleted`, `name`, `description`, `external_code`, `moment`, `applicable`, `sum`, `rate`, `owner_id`, `shared`, `group_id`, `organization_id`, `agent_id`, `created`, `payment_purpose`, `vat_sum`, `expense_item_id`)
1570 VALUES ('{$row->id}', '{$version}', '{$updated}', '{$deleted}', '{$name}', '{$description}', '{$externalCode}', '{$moment}', '{$applicable}', '{$sum}', '{$rateId}', '{$ownerId}', '{$shared}', '{$groupId}', '{$organizationId}', '{$agencyId}', '{$created}', '{$paymentPurpose}', '{$vatSum}', '{$expenseItemId}');
1571 ";
1572 $this->makeYiiOperation($sql);
1573
1574 }
1575 }
1576 }
1577 return true;
1578 }
1579 return false;
1580 }
1581
1582
1583 private function updateDemandTable()
1584 {
1585 $method = "entity/demand";
1586 $dataDecoded = $this->getAllRows($method, 100);
1587
1588 if (!empty($dataDecoded)) {
1589 foreach ($dataDecoded as $paginationItem) {
1590 if (!empty($paginationItem)) {
1591 foreach ($paginationItem as $row) {
1592 $demandId = $row->id;
1593 $dataOwnerDecoded = json_decode($this->curlPost($row->owner->meta->href, $this->username, $this->password));
1594 $dataAgencyDecoded = json_decode($this->curlPost($row->agent->meta->href, $this->username, $this->password));
1595 $dataOrganizationDecoded = json_decode($this->curlPost($row->organization->meta->href, $this->username, $this->password));
1596 $dataRateDecoded = json_decode($this->curlPost($row->rate->currency->meta->href, $this->username, $this->password));
1597 $dataStoreDecoded = json_decode($this->curlPost($row->store->meta->href, $this->username, $this->password));
1598 if (!empty($dataOwnerDecoded->id)) $ownerId = $dataOwnerDecoded->id; else $ownerId = null;
1599 if (!empty($dataAgencyDecoded->id)) $agencyId = $dataAgencyDecoded->id; else $agencyId = null;
1600 if (!empty($dataOrganizationDecoded->id)) $organizationId = $dataOrganizationDecoded->id; else $organizationId = null;
1601 if (!empty($dataStoreDecoded->id)) $storeId = $dataStoreDecoded->id; else $storeId = null;
1602 if (!empty($dataRateDecoded->code)) $rateId = $dataRateDecoded->code; else $rateId = null;
1603 if (!empty($row->version)) $version = $row->version; else $version = null;
1604 if (!empty($row->updated)) $updated = $row->updated; else $updated = null;
1605 if (!empty($row->name)) $name = $row->name; else $name = null;
1606 if (!empty($row->description)) $description = $row->name; else $description = null;
1607 if (!empty($row->externalCode)) $externalCode = $row->externalCode; else $externalCode = null;
1608 if (!empty($row->moment)) $moment = $row->moment; else $moment = null;
1609 if (!empty($row->sum)) $sum = $row->sum; else $sum = null;
1610 if (!empty($row->created)) $created = $row->created; else $created = null;
1611
1612 $groupId = $this->getGroupId($row->group->meta->href);
1613 $applicable = $this->checkIfApplicable($row);
1614 $shared = $this->checkIfShared($row);
1615 $positionsHref = $row->positions->meta->href;
1616 $vatEnabled = $this->checkIfVatEnable($row);
1617
1618 $this->updateDemandsPositionsArrayTable($demandId, $positionsHref);
1619 $sql = "
1620 INSERT INTO `{$this->demandTable}` (`demand_id`, `owner_id`, `shared`, `group_id`, `version`, `updated`, `name`, `description`, `external_code`, `moment`, `applicable`, `vat_enabled`, `rate`, `sum`, `store_id`, `agent_id`, `organization_id`, `created`)
1621 VALUES ('{$demandId}', '{$ownerId}', '{$shared}', '{$groupId}', '{$version}', '{$updated}', '{$name}', '{$description}', '{$externalCode}', '{$moment}', '{$applicable}', '{$vatEnabled}', '{$rateId}', '{$sum}', '{$storeId}', '{$agencyId}', '{$organizationId}', '{$created}');
1622 ";
1623 $this->makeYiiOperation($sql);
1624
1625 }
1626 }
1627 }
1628 return true;
1629 }
1630 return false;
1631 }
1632
1633
1634 private function updateDemandsPositionsArrayTable($demandId, $positionsHref)
1635 {
1636 $dataDecoded = json_decode($this->curlPost($positionsHref, $this->username, $this->password));
1637 foreach ($dataDecoded as $paginationItem) {
1638 if (!empty($paginationItem)) {
1639 foreach ($dataDecoded->rows as $row) {
1640 $this->updateDemandPositionsTable($row);
1641 $sql = "
1642 INSERT INTO `{$this->positionsDemandsArrayTable}` (`positions_array_id`, `position_id`)
1643 VALUES ('{$demandId}', '{$row->id}');
1644 ";
1645
1646 $this->makeYiiOperation($sql);
1647
1648 }
1649 }
1650 }
1651 return true;
1652 }
1653
1654 private function updateDemandPositionsTable($row)
1655 {
1656 $dataAssortmentDecoded = json_decode($this->curlPost($row->assortment->meta->href, $this->username, $this->password));
1657 if (!empty($row->quantity)) $quantity = $row->quantity; else $quantity = null;
1658 if (!empty($dataAssortmentDecoded->id)) $assortmentId = $dataAssortmentDecoded->id; else $assortmentId = null;
1659 if (!empty($row->price)) $price = $row->price; else $price = null;
1660 if (!empty($row->discount)) $discount = $row->discount; else $discount = null;
1661 if (!empty($row->vat)) $vat = $row->vat; else $vat = null;
1662 if (!empty($row->cost)) $cost = $row->cost; else $cost = null;
1663
1664 $sql = "
1665 INSERT INTO `{$this->positionsDemandTable}` (`position_id`, `quantity`, `price`, `discount`, `vat`, `assortment_id`, `cost`)
1666 VALUES ('{$row->id}', '{$quantity}', '{$price}', '{$discount}', '{$vat}', '{$assortmentId}', '{$cost}' );
1667 ";
1668
1669 $this->makeYiiOperation($sql);
1670
1671 }
1672
1673 private function updateSupplyTable()
1674 {
1675 $method = "entity/supply";
1676 $dataDecoded = $this->getAllRows($method, 100);
1677
1678 if (!empty($dataDecoded)) {
1679 foreach ($dataDecoded as $paginationItem) {
1680 if (!empty($paginationItem)) {
1681 foreach ($paginationItem as $row) {
1682
1683 $supplyId = $row->id;
1684 $dataOwnerDecoded = json_decode($this->curlPost($row->owner->meta->href, $this->username, $this->password));
1685 $dataAgencyDecoded = json_decode($this->curlPost($row->agent->meta->href, $this->username, $this->password));
1686 $dataOrganizationDecoded = json_decode($this->curlPost($row->organization->meta->href, $this->username, $this->password));
1687 $dataRateDecoded = json_decode($this->curlPost($row->rate->currency->meta->href, $this->username, $this->password));
1688 $dataStoreDecoded = json_decode($this->curlPost($row->store->meta->href, $this->username, $this->password));
1689 if (!empty($dataOwnerDecoded->id)) $ownerId = $dataOwnerDecoded->id; else $ownerId = null;
1690 if (!empty($dataAgencyDecoded->id)) $agencyId = $dataAgencyDecoded->id; else $agencyId = null;
1691 if (!empty($dataOrganizationDecoded->id)) $organizationId = $dataOrganizationDecoded->id; else $organizationId = null;
1692 if (!empty($dataStoreDecoded->id)) $storeId = $dataStoreDecoded->id; else $storeId = null;
1693 if (!empty($dataRateDecoded->code)) $rateId = $dataRateDecoded->code; else $rateId = null;
1694 if (!empty($row->version)) $version = $row->version; else $version = null;
1695 if (!empty($row->updated)) $updated = $row->updated; else $updated = null;
1696 if (!empty($row->name)) $name = $row->name; else $name = null;
1697 if (!empty($row->description)) $description = $row->name; else $description = null;
1698 if (!empty($row->externalCode)) $externalCode = $row->externalCode; else $externalCode = null;
1699 if (!empty($row->moment)) $moment = $row->moment; else $moment = null;
1700 if (!empty($row->sum)) $sum = $row->sum; else $sum = null;
1701 if (!empty($row->created)) $created = $row->created; else $created = null;
1702
1703 $groupId = $this->getGroupId($row->group->meta->href);
1704 $applicable = $this->checkIfApplicable($row);
1705 $shared = $this->checkIfShared($row);
1706 $positionsHref = $row->positions->meta->href;
1707 $vatEnabled = $this->checkIfVatEnable($row);
1708
1709 $this->updateSupplyPositionsArrayTable($supplyId, $positionsHref);
1710 $sql = "
1711 INSERT INTO `{$this->supplyTable}` (`demand_id`, `owner_id`, `shared`, `group_id`, `version`, `updated`, `name`, `description`, `external_code`, `moment`, `applicable`, `vat_enabled`, `rate`, `sum`, `store_id`, `agent_id`, `organization_id`, `created`)
1712 VALUES ('{$supplyId}', '{$ownerId}', '{$shared}', '{$groupId}', '{$version}', '{$updated}', '{$name}', '{$description}', '{$externalCode}', '{$moment}', '{$applicable}', '{$vatEnabled}', '{$rateId}', '{$sum}', '{$storeId}', '{$agencyId}', '{$organizationId}', '{$created}');
1713 ";
1714
1715 $this->makeYiiOperation($sql);
1716
1717 }
1718 }
1719 }
1720 return true;
1721 }
1722 return false;
1723 }
1724
1725 private function updateSupplyPositionsArrayTable($supplyId, $positionsHref)
1726 {
1727 $dataDecoded = json_decode($this->curlPost($positionsHref, $this->username, $this->password));
1728 foreach ($dataDecoded as $paginationItem) {
1729 if (!empty($paginationItem)) {
1730 foreach ($dataDecoded->rows as $row) {
1731 $this->updateSupplyPositionsTable($row);
1732 $sql = "
1733 INSERT INTO `{$this->positionsSuppliesArrayTable}` (`positions_array_id`, `position_id`)
1734 VALUES ('{$supplyId}', '{$row->id}');
1735 ";
1736
1737 $this->makeYiiOperation($sql);
1738
1739 }
1740 }
1741 }
1742 return true;
1743 }
1744
1745 private function updateSupplyPositionsTable($row)
1746 {
1747 $dataAssortmentDecoded = json_decode($this->curlPost($row->assortment->meta->href, $this->username, $this->password));
1748 $dataCountryDecoded = json_decode($this->curlPost($row->country->meta->href, $this->username, $this->password));
1749 if (!empty($row->quantity)) $quantity = $row->quantity; else $quantity = null;
1750 if (!empty($dataAssortmentDecoded->id)) $assortmentId = $dataAssortmentDecoded->id; else $assortmentId = null;
1751 if (!empty($dataCountryDecoded->id)) $countryId = $dataCountryDecoded->id; else $countryId = null;
1752 if (!empty($row->price)) $price = $row->price; else $price = null;
1753 if (!empty($row->discount)) $discount = $row->discount; else $discount = null;
1754 if (!empty($row->vat)) $vat = $row->vat; else $vat = null;
1755 if (!empty($row->gtd)) $gtd = $row->gtd; else $gtd = null;
1756
1757 $sql = "
1758 INSERT INTO `{$this->positionsSupplyTable}` (`position_id`, `quantity`, `price`, `discount`, `vat`, `assortment_id`, `gtd`, `country_id`)
1759 VALUES ('{$row->id}', '{$quantity}', '{$price}', '{$discount}', '{$vat}', '{$assortmentId}', '{$gtd}', '{$countryId}');
1760 ";
1761 $this->makeYiiOperation($sql);
1762
1763 }
1764
1765 private function updateLossTable()
1766 {
1767 $method = "entity/loss";
1768 $dataDecoded = $this->getAllRows($method, 100);
1769
1770 if (!empty($dataDecoded)) {
1771 foreach ($dataDecoded as $paginationItem) {
1772 if (!empty($paginationItem)) {
1773 foreach ($paginationItem as $row) {
1774 $dataOwnerDecoded = json_decode($this->curlPost($row->{'owner'}->{'meta'}->{'href'}, $this->username, $this->password));
1775 $dataGroupDecoded = json_decode($this->curlPost($row->{'group'}->{'meta'}->{'href'}, $this->username, $this->password));
1776 $dataStoreDecoded = json_decode($this->curlPost($row->{'store'}->{'meta'}->{'href'}, $this->username, $this->password));
1777 $dataPositionsDecoded = json_decode($this->curlPost($row->{'positions'}->{'meta'}->{'href'}, $this->username, $this->password));
1778
1779 if (!empty($dataOwnerDecoded->{'sum'})) $sum = $row->{'sum'}; else $sum = null;
1780 if (!empty($dataOwnerDecoded->{'vatSum'})) $vatSum = $row->{'vatSum'}; else $vatSum = null;
1781 if (!empty($dataPositionsDecoded->{'quantity'})) $quantity = $dataPositionsDecoded->{'quantity'}; else $quantity = null;
1782 if (!empty($dataPositionsDecoded->{'price'})) $price = $dataPositionsDecoded->{'price'}; else $price = null;
1783 if (!empty($dataPositionsDecoded->{'discount'})) $discount = $dataPositionsDecoded->{'discount'}; else $discount = null;
1784
1785 $sql = "
1786 INSERT INTO `{$this->lossTable}` (`login`, `loss_id`, `created`, `name`, `owner_name`, `owner_email`, `owner_phone`, `owner_sum`, `owner_vat_sum`, `group_name`, `store_name`, `position_quantity`, `position_price`, `position_discount`)
1787 VALUES ('{$this->login}', '{$row->{'id'}}', '{$row->{'created'}}', '{$row->{'name'}}', '{$dataOwnerDecoded->{'name'}}', '{$dataOwnerDecoded->{'email'}}', '{$dataOwnerDecoded->{'phone'}}', '{$sum}', '{$vatSum}', '{$dataGroupDecoded->{'name'}}', '{$dataStoreDecoded->{'name'}}', '{$quantity}', '{$price}', '{$discount}');
1788 ";
1789 $this->makeYiiOperation($sql);
1790
1791 }
1792 }
1793 }
1794 return true;
1795 }
1796 return false;
1797 }
1798
1799 private function updateMoveTable()
1800 {
1801 $method = "entity/move";
1802 $dataDecoded = $this->getAllRows($method, 100);
1803
1804 if (!empty($dataDecoded)) {
1805 foreach ($dataDecoded as $paginationItem) {
1806 if (!empty($paginationItem)) {
1807 foreach ($paginationItem as $row) {
1808 $dataOwnerDecoded = json_decode($this->curlPost($row->{'owner'}->{'meta'}->{'href'}, $this->username, $this->password));
1809 $dataGroupDecoded = json_decode($this->curlPost($row->{'group'}->{'meta'}->{'href'}, $this->username, $this->password));
1810 $dataPositionsDecoded = json_decode($this->curlPost($row->{'positions'}->{'meta'}->{'href'}, $this->username, $this->password));
1811 $dataSourceStoreDecoded = json_decode($this->curlPost($row->{'sourceStore'}->{'meta'}->{'href'}, $this->username, $this->password));
1812 $dataTargetStoreDecoded = json_decode($this->curlPost($row->{'targetStore'}->{'meta'}->{'href'}, $this->username, $this->password));
1813
1814 if (!empty($dataOwnerDecoded->{'sum'})) $sum = $row->{'sum'}; else $sum = null;
1815 if (!empty($dataOwnerDecoded->{'vatSum'})) $vatSum = $row->{'vatSum'}; else $vatSum = null;
1816 if (!empty($dataPositionsDecoded->{'quantity'})) $quantity = $dataPositionsDecoded->{'quantity'}; else $quantity = null;
1817 if (!empty($dataPositionsDecoded->{'price'})) $price = $dataPositionsDecoded->{'price'}; else $price = null;
1818 if (!empty($dataPositionsDecoded->{'discount'})) $discount = $dataPositionsDecoded->{'discount'}; else $discount = null;
1819
1820 $sql = "
1821 INSERT INTO `{$this->moveTable}` (`login`, `move_id`, `name`, `sum`, `owner_name`, `owner_email`, `owner_phone`, `owner_sum`, `owner_vat_sum`, `group_name`, `position_quantity`, `position_price`, `position_discount`, `source_store_name`, `target_store_name`)
1822 VALUES ('{$this->login}', '{$row->{'id'}}', '{$row->{'name'}}', '{$row->{'sum'}}', '{$dataOwnerDecoded->{'name'}}', '{$dataOwnerDecoded->{'email'}}', '{$dataOwnerDecoded->{'phone'}}', '{$sum}', '{$vatSum}', '{$dataGroupDecoded->{'name'}}', '{$quantity}', '{$price}', '{$discount}', '{$dataSourceStoreDecoded->{'name'}}', '{$dataTargetStoreDecoded->{'name'}}');
1823 ";
1824 $this->makeYiiOperation($sql);
1825 }
1826 }
1827 }
1828 return true;
1829 }
1830 return false;
1831 }
1832
1833 private function updateRetaildemandTable()
1834 {
1835 $method = "entity/retaildemand";
1836 $dataDecoded = $this->getAllRows($method, 100);
1837
1838 if (!empty($dataDecoded)) {
1839 foreach ($dataDecoded as $paginationItem) {
1840 if (!empty($paginationItem)) {
1841 foreach ($paginationItem as $row) {
1842 var_dump($row);
1843 }
1844 }
1845 }
1846 return true;
1847 }
1848 return false;
1849 }
1850
1851 private function updateRetailsalesreturnTable()
1852 {
1853 $method = "entity/retailsalesreturn";
1854 $dataDecoded = $this->getAllRows($method, 100);
1855
1856 if (!empty($dataDecoded)) {
1857 foreach ($dataDecoded as $paginationItem) {
1858 if (!empty($paginationItem)) {
1859 foreach ($paginationItem as $row) {
1860 var_dump($row);
1861 }
1862 }
1863 }
1864 return true;
1865 }
1866 return false;
1867 }
1868
1869 private function updateRetaildrawerCashInTable()
1870 {
1871 $method = "entity/retaildrawercashin";
1872 $dataDecoded = $this->getAllRows($method, 100);
1873
1874 if (!empty($dataDecoded)) {
1875 foreach ($dataDecoded as $paginationItem) {
1876 if (!empty($paginationItem)) {
1877 foreach ($paginationItem as $row) {
1878 var_dump($row);
1879 }
1880 }
1881 }
1882 return true;
1883 }
1884 return false;
1885 }
1886
1887 private function updateRetaildrawerCashOutTable()
1888 {
1889 $method = "entity/retaildrawercashout";
1890 $dataDecoded = $this->getAllRows($method, 100);
1891
1892 if (!empty($dataDecoded)) {
1893 foreach ($dataDecoded as $paginationItem) {
1894 if (!empty($paginationItem)) {
1895 foreach ($paginationItem as $row) {
1896 var_dump($row);
1897 }
1898 }
1899 }
1900 return true;
1901 }
1902 return false;
1903 }
1904
1905
1906 private function updateSalesReturnTable()
1907 {
1908 $method = "entity/salesreturn";
1909 $dataDecoded = $this->getAllRows($method, 100);
1910
1911 if (!empty($dataDecoded)) {
1912 foreach ($dataDecoded as $paginationItem) {
1913 if (!empty($paginationItem)) {
1914 foreach ($paginationItem as $row) {
1915 var_dump($row);
1916 }
1917 }
1918 }
1919 return true;
1920 }
1921 return false;
1922 }
1923
1924
1925 private function updatePurchasereturn()
1926 {
1927 $method = "entity/purchasereturn";
1928 $dataDecoded = $this->getAllRows($method, 100);
1929
1930 if (!empty($dataDecoded)) {
1931 foreach ($dataDecoded as $paginationItem) {
1932 if (!empty($paginationItem)) {
1933 foreach ($paginationItem as $row) {
1934 var_dump($row);
1935 }
1936 }
1937 }
1938 return true;
1939 }
1940 return false;
1941 }
1942
1943
1944 private function updateFactureout()
1945 {
1946 $method = "entity/factureout";
1947 $dataDecoded = $this->getAllRows($method, 100);
1948
1949 if (!empty($dataDecoded)) {
1950 foreach ($dataDecoded as $paginationItem) {
1951 if (!empty($paginationItem)) {
1952 foreach ($paginationItem as $row) {
1953 var_dump($row);
1954 }
1955 }
1956 }
1957 return true;
1958 }
1959 return false;
1960 }
1961
1962 private function updateFacturein()
1963 {
1964 $method = "entity/facturein";
1965 $dataDecoded = $this->getAllRows($method, 100);
1966
1967 if (!empty($dataDecoded)) {
1968 foreach ($dataDecoded as $paginationItem) {
1969 if (!empty($paginationItem)) {
1970 foreach ($paginationItem as $row) {
1971 var_dump($row);
1972 }
1973 }
1974 }
1975 return true;
1976 }
1977 return false;
1978 }
1979
1980
1981 private function updateInventoryTable()
1982 {
1983 $method = "entity/inventory";
1984 $dataDecoded = $this->getAllRows($method, 100);
1985
1986 if (!empty($dataDecoded)) {
1987 foreach ($dataDecoded as $paginationItem) {
1988 if (!empty($paginationItem)) {
1989 foreach ($paginationItem as $row) {
1990 $dataOwnerDecoded = json_decode($this->curlPost($row->{'owner'}->{'meta'}->{'href'}, $this->username, $this->password));
1991 $dataGroupDecoded = json_decode($this->curlPost($row->{'group'}->{'meta'}->{'href'}, $this->username, $this->password));
1992 $dataStoreDecoded = json_decode($this->curlPost($row->{'store'}->{'meta'}->{'href'}, $this->username, $this->password));
1993 $dataPositionsDecoded = json_decode($this->curlPost($row->{'positions'}->{'meta'}->{'href'}, $this->username, $this->password));
1994
1995 if (!empty($dataOwnerDecoded->{'sum'})) $sum = $row->{'sum'}; else $sum = null;
1996 if (!empty($dataOwnerDecoded->{'vatSum'})) $vatSum = $row->{'vatSum'}; else $vatSum = null;
1997 if (!empty($dataPositionsDecoded->{'quantity'})) $quantity = $dataPositionsDecoded->{'quantity'}; else $quantity = null;
1998 if (!empty($dataPositionsDecoded->{'price'})) $price = $dataPositionsDecoded->{'price'}; else $price = null;
1999 if (!empty($dataPositionsDecoded->{'discount'})) $discount = $dataPositionsDecoded->{'discount'}; else $discount = null;
2000
2001 $sql = "
2002 INSERT INTO `{$this->inventoryTable}` (`login`, `inventory_id`, `name`, `sum`, `owner_name`, `owner_email`, `owner_phone`, `owner_sum`, `owner_vat_sum`, `group_name`, `store_name`, `position_quantity`, `position_price`, `position_discount`)
2003 VALUES ('{$this->login}', '{$row->{'id'}}', '{$row->{'name'}}', '{$row->{'sum'}}', '{$dataOwnerDecoded->{'name'}}', '{$dataOwnerDecoded->{'email'}}', '{$dataOwnerDecoded->{'phone'}}', '{$sum}', '{$vatSum}', '{$dataGroupDecoded->{'name'}}', '{$dataStoreDecoded->{'name'}}', '{$quantity}', '{$price}', '{$discount}');
2004 ";
2005 $this->makeYiiOperation($sql);
2006
2007 }
2008 }
2009 }
2010 return true;
2011 }
2012 return false;
2013 }
2014
2015 private function updateCommissionreportin()
2016 {
2017 $method = "entity/commissionreportin";
2018 $dataDecoded = $this->getAllRows($method, 100);
2019
2020 if (!empty($dataDecoded)) {
2021 foreach ($dataDecoded as $paginationItem) {
2022 if (!empty($paginationItem)) {
2023 foreach ($paginationItem as $row) {
2024 var_dump($row);
2025 }
2026 }
2027 }
2028 return true;
2029 }
2030 return false;
2031 }
2032
2033 private function updateCommissionreportout()
2034 {
2035 $method = "entity/commissionreportout";
2036 $dataDecoded = $this->getAllRows($method, 100);
2037
2038 if (!empty($dataDecoded)) {
2039 foreach ($dataDecoded as $paginationItem) {
2040 if (!empty($paginationItem)) {
2041 foreach ($paginationItem as $row) {
2042 var_dump($row);
2043 }
2044 }
2045 }
2046 return true;
2047 }
2048 return false;
2049 }
2050
2051 private function updatePricelist()
2052 {
2053 $method = "entity/pricelist";
2054 $dataDecoded = $this->getAllRows($method, 100);
2055
2056 if (!empty($dataDecoded)) {
2057 foreach ($dataDecoded as $paginationItem) {
2058 if (!empty($paginationItem)) {
2059 foreach ($paginationItem as $row) {
2060 var_dump($row);
2061 }
2062 }
2063 }
2064 return true;
2065 }
2066 return false;
2067 }
2068
2069 private function updateProcessingplan()
2070 {
2071 $method = "entity/processingplan";
2072 $dataDecoded = $this->getAllRows($method, 100);
2073
2074 if (!empty($dataDecoded)) {
2075 foreach ($dataDecoded as $paginationItem) {
2076 if (!empty($paginationItem)) {
2077 foreach ($paginationItem as $row) {
2078 var_dump($row);
2079 }
2080 }
2081 }
2082 return true;
2083 }
2084 return false;
2085 }
2086
2087 private function updateProcessingOrderTable()
2088 {
2089 $method = "entity/processingorder";
2090 $dataDecoded = $this->getAllRows($method, 100);
2091
2092 if (!empty($dataDecoded)) {
2093 foreach ($dataDecoded as $paginationItem) {
2094 if (!empty($paginationItem)) {
2095 foreach ($paginationItem as $row) {
2096 $dataOwnerDecoded = json_decode($this->curlPost($row->{'owner'}->{'meta'}->{'href'}, $this->username, $this->password));
2097 $dataGroupDecoded = json_decode($this->curlPost($row->{'group'}->{'meta'}->{'href'}, $this->username, $this->password));
2098
2099 if (!empty($dataOwnerDecoded->{'sum'})) $sum = $row->{'sum'}; else $sum = null;
2100 if (!empty($dataOwnerDecoded->{'vatSum'})) $vatSum = $row->{'vatSum'}; else $vatSum = null;
2101
2102 $sql = "
2103 INSERT INTO `{$this->processingOrderTable}` (`login`, `processing_order_id`, `name`, `quantity`, `owner_name`, `owner_email`, `owner_phone`, `owner_sum`, `owner_vat_sum`, `group_name`)
2104 VALUES ('{$this->login}', '{$row->{'id'}}', '{$row->{'name'}}', '{$row->{'quantity'}}', '{$dataOwnerDecoded->{'name'}}', '{$dataOwnerDecoded->{'email'}}', '{$dataOwnerDecoded->{'phone'}}', '{$sum}', '{$vatSum}', '{$dataGroupDecoded->{'name'}}');
2105 ";
2106 $this->makeYiiOperation($sql);
2107
2108 }
2109 }
2110 }
2111 return true;
2112 }
2113 return false;
2114 }
2115
2116 private function updateProcessing()
2117 {
2118 $method = "entity/processing";
2119 $dataDecoded = $this->getAllRows($method, 100);
2120
2121 if (!empty($dataDecoded)) {
2122 foreach ($dataDecoded as $paginationItem) {
2123 if (!empty($paginationItem)) {
2124 foreach ($paginationItem as $row) {
2125 var_dump($row);
2126 }
2127 }
2128 }
2129 return true;
2130 }
2131 return false;
2132 }
2133
2134 private function updateInternalorder()
2135 {
2136 $method = "entity/internalorder";
2137 $dataDecoded = $this->getAllRows($method, 100);
2138
2139 if (!empty($dataDecoded)) {
2140 foreach ($dataDecoded as $paginationItem) {
2141 if (!empty($paginationItem)) {
2142 foreach ($paginationItem as $row) {
2143 var_dump($row);
2144 }
2145 }
2146 }
2147 return true;
2148 }
2149 return false;
2150 }
2151
2152 private function updateStockAllTable()
2153 {
2154 $method = "report/stock/all";
2155 $dataDecoded = $this->getAllRows($method, 100);
2156
2157 if (!empty($dataDecoded)) {
2158 foreach ($dataDecoded as $paginationItem) {
2159 if (!empty($paginationItem)) {
2160 foreach ($paginationItem as $row) {
2161 $sql = "
2162 INSERT INTO `{$this->stockAllTable}` (`login`, `stock`, `in_transit`, `reserve`, `quantity`, `name`, `code`, `price`, `sale_price`)
2163 VALUES ('{$this->login}', '{$row->{'stock'}}', '{$row->{'inTransit'}}', '{$row->{'reserve'}}', '{$row->{'quantity'}}', '{$row->{'name'}}', '{$row->{'code'}}', '{$row->{'price'}}', '{$row->{'salePrice'}}');
2164 ";
2165
2166 $this->makeYiiOperation($sql);
2167
2168 }
2169 }
2170 }
2171 return true;
2172 }
2173 return false;
2174 }
2175
2176 private function updateStockBySort()
2177 {
2178 $method = "report/stock/bystore";
2179 $dataDecoded = $this->getAllRows($method, 100);
2180
2181 if (!empty($dataDecoded)) {
2182 foreach ($dataDecoded as $paginationItem) {
2183 if (!empty($paginationItem)) {
2184 foreach ($paginationItem as $row) {
2185 var_dump($row);
2186 }
2187 }
2188 }
2189 return true;
2190 }
2191 return false;
2192 }
2193
2194 private function updateReportCounterparty()
2195 {
2196 $method = "report/counterparty";
2197 $dataDecoded = $this->getAllRows($method, 100);
2198
2199 if (!empty($dataDecoded)) {
2200 foreach ($dataDecoded as $paginationItem) {
2201 if (!empty($paginationItem)) {
2202 foreach ($paginationItem as $row) {
2203 var_dump($row);
2204 }
2205 }
2206 }
2207 return true;
2208 }
2209 return false;
2210 }
2211
2212
2213 private function updateReportDashboardDayTable()
2214 {
2215 $method = "/report/dashboard/day";
2216 $dataDecoded = json_decode($this->moySkladApi($method));
2217
2218 if (!empty($dataDecoded)) {
2219 var_dump($dataDecoded->sales->count);
2220 return true;
2221 }
2222 return false;
2223 }
2224
2225 private function updateReportDashboardWeekTable()
2226 {
2227 $method = "/report/dashboard/week";
2228 $dataDecoded = json_decode($this->moySkladApi($method));
2229
2230 if (!empty($dataDecoded)) {
2231 var_dump($dataDecoded->sales->count);
2232 return true;
2233 }
2234 return false;
2235 }
2236
2237 private function updateReportDashboardMonthTable()
2238 {
2239 $method = "/report/dashboard/month";
2240 $dataDecoded = json_decode($this->moySkladApi($method));
2241
2242 if (!empty($dataDecoded)) {
2243 var_dump($dataDecoded->sales->count);
2244 return true;
2245 }
2246 return false;
2247 }
2248
2249 private function updateAuditTable()
2250 {
2251 $method = "audit";
2252 $dataDecoded = $this->getAllRows($method, 100);
2253
2254 if (!empty($dataDecoded)) {
2255 foreach ($dataDecoded as $paginationItem) {
2256 if (!empty($paginationItem)) {
2257 foreach ($paginationItem as $row) {
2258 var_dump($row->id);
2259 $sql = "
2260 INSERT INTO `{$this->auditTable}` (`login`, `audit_id`, `uid`)
2261 VALUES ('{$this->login}', '{$row->{'id'}}', '{$row->{'uid'}}');
2262 ";
2263 $this->makeYiiOperation($sql);
2264
2265 }
2266 }
2267 }
2268 return true;
2269 }
2270 return false;
2271 }
2272
2273
2274 private function updateMonthTable()
2275 {
2276 $offset = 0;
2277 $method = "report/dashboard/month?limit={$this->limit}&offset={$offset}";
2278 $response = $this->moySkladApi($method);
2279 var_dump($response);
2280
2281 $dataDecoded = json_decode($response);
2282 if (!empty($dataDecoded)) {
2283 $sql = "
2284 INSERT INTO `{$this->reportDashboardMonthTable}` (`login`, `sales_count`, `sales_amount`, `sales_movement_amount`, `orders_count`, `orders_amount`, `orders_movement_amount`, `income`, `outcome`, `balance`, `today_movement`, `movement`)
2285 VALUES ('{$this->login}', '{$dataDecoded->{'sales'}->{'count'}}', '{$dataDecoded->{'sales'}->{'amount'}}', '{$dataDecoded->{'sales'}->{'movementAmount'}}', '{$dataDecoded->{'orders'}->{'count'}}', '{$dataDecoded->{'orders'}->{'amount'}}', '{$dataDecoded->{'orders'}->{'movementAmount'}}', '{$dataDecoded->{'money'}->{'income'}}', '{$dataDecoded->{'money'}->{'outcome'}}', '{$dataDecoded->{'money'}->{'balance'}}', '{$dataDecoded->{'money'}->{'todayMovement'}}', '{$dataDecoded->{'money'}->{'movement'}}');
2286 ";
2287 $this->makeYiiOperation($sql);
2288
2289
2290 return true;
2291 }
2292
2293 return false;
2294 }
2295
2296
2297 private function curlPost($url, $username, $password)
2298 {
2299 $curl = curl_init();
2300 curl_setopt($curl, CURLOPT_USERPWD, $username . ":" . $password);
2301 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
2302 curl_setopt($curl, CURLOPT_URL, $url);
2303 $result = curl_exec($curl);
2304 curl_close($curl);
2305 return $result;
2306 }
2307
2308 private function moySkladApi($method)
2309 {
2310 $response = $this->curlPost("https://online.moysklad.ru/api/remap/1.1/{$method}", $this->username, $this->password);
2311 return $response;
2312 }
2313
2314 private function getAllRows($method, $limit = 100)
2315 {
2316 $start = microtime(true);
2317
2318 $this->makeSomeLogBitch($method);
2319
2320 $offset = 0;
2321 $response = json_decode($this->moySkladApi("{$method}?limit=1&offset={$offset}"));
2322
2323 $size = $response->meta->size;
2324 $iteration = ceil($size / $limit);
2325 $data = [];
2326
2327 for ($i = 1; $i <= $iteration; $i++) {
2328 $response = json_decode($this->moySkladApi("{$method}?limit={$limit}&offset={$offset}"));
2329 $data[] = $response->rows;
2330 $offset += $limit;
2331 }
2332
2333 $time = microtime(true) - $start;
2334 printf("Выгрузка длилаÑÑŒ %.4F Ñек.", $time);
2335 echo "\n";
2336
2337
2338 return $data;
2339
2340
2341 }
2342
2343 private function makeAuth()
2344 {
2345 $method = "/report/dashboard/day";
2346 $dataDecoded = json_decode($this->moySkladApi($method));
2347 if ($dataDecoded->errors) {
2348 echo "Ошибка аутентификации: Ðеправильный пароль или Ð¸Ð¼Ñ Ð¿Ð¾Ð»ÑŒÐ·Ð¾Ð²Ð°Ñ‚ÐµÐ»Ñ";
2349 return false;
2350 } else {
2351 return true;
2352 }
2353 }
2354
2355 private function checkIfArchived($row)
2356 {
2357 if ($row->archived) {
2358 $archived = "Заархивировано";
2359 } else {
2360 $archived = "Ðе в архиве";
2361 }
2362 return $archived;
2363 }
2364
2365 private function checkIfShared($row)
2366 {
2367 if ($row->shared) {
2368 $shared = "Общий доÑтуп";
2369 } else {
2370 $shared = "Приватный доÑтуп";
2371 }
2372 return $shared;
2373 }
2374
2375 private function checkIfApplicable($row)
2376 {
2377 if ($row->applicable) {
2378 $applicable = "Проведен";
2379 } else {
2380 $applicable = "Ðе проведен";
2381 }
2382 return $applicable;
2383 }
2384
2385 private function checkIfEgaisEnable($row)
2386 {
2387 if ($row->shared) {
2388 $shared = "ЕГÐИС включен";
2389 } else {
2390 $shared = "ЕГÐИС выключен";
2391 }
2392 return $shared;
2393 }
2394
2395 private function checkPayerVat($row)
2396 {
2397 if ($row->shared) {
2398 $shared = "Плательщик ÐДС";
2399 } else {
2400 $shared = "Ðе плательщик ÐДС";
2401 }
2402 return $shared;
2403 }
2404
2405 private function checkIsDefault($row)
2406 {
2407 if ($row->isDefault) {
2408 $isDefault = "ОÑновной Ñчёт";
2409 } else {
2410 $isDefault = "Ðе оÑновной Ñчёт";
2411 }
2412 return $isDefault;
2413 }
2414
2415 private function getCompanyType($row)
2416 {
2417 switch ($row->companyType) {
2418 case "legal":
2419 $companyType = "ЮридичеÑкое лицо";
2420 break;
2421 case "entrepreneur":
2422 $companyType = "Индивидуальный предприниматель";
2423 break;
2424 case "individual":
2425 $companyType = "ФизичеÑкое лицо";
2426 break;
2427 }
2428 return $companyType;
2429 }
2430
2431 private function checkIfVatEnable($row)
2432 {
2433 if ($row->shared) {
2434 $shared = "ÐДС учитываетÑÑ";
2435 } else {
2436 $shared = "ÐДС не учитываетÑÑ";
2437 }
2438 return $shared;
2439 }
2440
2441 private function getGroupId($group_id)
2442 {
2443 return substr($group_id, 54);
2444 }
2445
2446 private function makeSomeLogBitch($method)
2447 {
2448 echo "Ðачинаем выгрузку-хуигрузку " . $method . "\n";
2449 }
2450
2451 private function makeYiiOperation($sql)
2452 {
2453// $command = \Yii::$app->mysklad_db->createCommand($sql);
2454//
2455// try {
2456// $command->execute();
2457// } catch (\yii\db\Exception $e) {
2458// parent::log($e->getMessage());
2459// }
2460 }
2461
2462 private function createTable()
2463 {
2464 $sql = "
2465 CREATE TABLE IF NOT EXISTS `{$this->counterPartyTable}` (
2466 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
2467 `counter_party_id` varchar(255),
2468 `owner_id` varchar(255),
2469 `group_id` varchar(255),
2470 `shared` varchar(255),
2471 `version` varchar(255),
2472 `updated` varchar(255),
2473 `name` varchar(255),
2474 `description` varchar(255),
2475 `code` varchar(255),
2476 `external_code` varchar(255),
2477 `archived` varchar(255),
2478 `created` varchar(255),
2479 `email` varchar(255),
2480 `phone` varchar(255),
2481 `fax` varchar(255),
2482 `actual_address` varchar(255),
2483 `company_type` varchar(255),
2484 `legal_title` varchar(255),
2485 `legal_address` varchar(255),
2486 `inn` varchar(255),
2487 `kpp` varchar(255),
2488 `ogrn` varchar(255),
2489 `okpo` varchar(255),
2490 `ogrnip` varchar(255),
2491 `certificateNumber` varchar(255),
2492 `certificateDate` varchar(255),
2493 `discount_card_number` varchar(255),
2494 `state_type` varchar(255),
2495 `sales_amount` varchar(255)
2496 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2497
2498 CREATE TABLE IF NOT EXISTS `{$this->assortmentTable}` (
2499 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
2500 `assortment_id` varchar(255) NOT NULL,
2501 `owner_id` varchar(255) NOT NULL,
2502 `group_id` varchar(255) NOT NULL,
2503 `shared` varchar(255) NOT NULL,
2504 `version` text NOT NULL,
2505 `updated` text NOT NULL,
2506 `name` varchar(255) NOT NULL,
2507 `code` varchar(255) NOT NULL,
2508 `external_code` varchar(255) NOT NULL,
2509 `archived` text NOT NULL,
2510 `path_name` varchar(255) NOT NULL,
2511 `uom_id` varchar(255) NOT NULL,
2512 `min_price` varchar(255) NOT NULL,
2513 `weight` varchar(255) NOT NULL,
2514 `volume` varchar(255) NOT NULL,
2515 `is_serial_trackable` varchar(255) NOT NULL,
2516 `stock` varchar(255) NOT NULL,
2517 `reserve` varchar(255) NOT NULL,
2518 `in_transit` varchar(255) NOT NULL,
2519 `quantity` varchar(255) NOT NULL
2520 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2521
2522 CREATE TABLE IF NOT EXISTS `{$this->currencyTable}` (
2523 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
2524 `code` varchar(255) NOT NULL,
2525 `name` varchar(255) NOT NULL,
2526 `full_name` varchar(255) NOT NULL,
2527 `iso_code` varchar(255) NOT NULL
2528 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2529
2530 CREATE TABLE IF NOT EXISTS `{$this->productTable}` (
2531 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
2532 `product_id` varchar(255) NOT NULL,
2533 `owner_id` varchar(255) NOT NULL,
2534 `shared` varchar(255) NOT NULL,
2535 `group_id` varchar(255) NOT NULL,
2536 `version` varchar(255) NOT NULL,
2537 `updated` varchar(255) NOT NULL,
2538 `name` varchar(255) NOT NULL,
2539 `description` varchar(255) NOT NULL,
2540 `code` varchar(255) NOT NULL,
2541 `external_code` varchar(255) NOT NULL,
2542 `archived` varchar(255) NOT NULL,
2543 `path_name` varchar(255) NOT NULL,
2544 `vat` varchar(255) NOT NULL,
2545 `effective_vat` varchar(255) NOT NULL,
2546 `uom` varchar(255) NOT NULL,
2547 `min_price` varchar(255) NOT NULL,
2548 `buy_price` varchar(255) NOT NULL,
2549 `modifications_count` varchar(255) NOT NULL,
2550 `minimum_balance` varchar(255) NOT NULL,
2551 `is_serial_trackable` varchar(255) NOT NULL
2552 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2553
2554 CREATE TABLE IF NOT EXISTS `{$this->productFolderTable}` (
2555 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
2556 `product_folder_id` varchar(255) NOT NULL,
2557 `owner_id` varchar(255) NOT NULL,
2558 `shared` varchar(255) NOT NULL,
2559 `group_id` varchar(255) NOT NULL,
2560 `version` text NOT NULL,
2561 `updated` varchar(255) NOT NULL,
2562 `name` varchar(255) NOT NULL,
2563 `description` varchar(255) NOT NULL,
2564 `code` varchar(255) NOT NULL,
2565 `external_code` varchar(255) NOT NULL,
2566 `archived` varchar(255) NOT NULL,
2567 `path_name` varchar(255) NOT NULL,
2568 `vat` varchar(255) NOT NULL,
2569 `effective_vat` varchar(255) NOT NULL
2570 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2571
2572 CREATE TABLE IF NOT EXISTS `{$this->projectTable}` (
2573 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
2574 `project_id` varchar(255) NOT NULL,
2575 `owner_id` varchar(255) NOT NULL,
2576 `shared` varchar(255) NOT NULL,
2577 `group_id` varchar(255) NOT NULL,
2578 `version` text NOT NULL,
2579 `updated` varchar(255) NOT NULL,
2580 `name` varchar(255) NOT NULL,
2581 `description` varchar(255) NOT NULL,
2582 `code` varchar(255) NOT NULL,
2583 `external_code` varchar(255) NOT NULL,
2584 `archived` varchar(255) NOT NULL
2585 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2586
2587 CREATE TABLE IF NOT EXISTS `{$this->expenseItemTable}` (
2588 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
2589 `expense_item_id` varchar(255) NOT NULL,
2590 `version` varchar(255) NOT NULL,
2591 `updated` varchar(255) NOT NULL,
2592 `name` varchar(255) NOT NULL,
2593 `description` text NOT NULL,
2594 `code` varchar(255) NOT NULL,
2595 `external_code` varchar(255) NOT NULL
2596 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2597
2598 CREATE TABLE IF NOT EXISTS `{$this->countriesTable}` (
2599 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
2600 `country_id` int(11) NOT NULL,
2601 `name` varchar(255) NOT NULL,
2602 `description` varchar(255) NOT NULL,
2603 `code` varchar(255) NOT NULL,
2604 `external_code` varchar(255) NOT NULL,
2605 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2606
2607 CREATE TABLE IF NOT EXISTS `{$this->groupsTable}` (
2608 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
2609 `login` varchar(255) NOT NULL,
2610 `name` text NOT NULL
2611 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2612
2613 CREATE TABLE IF NOT EXISTS `{$this->uomTable}` (
2614 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
2615 `uom_id` int(11) NOT NULL,
2616 `version` int(11) NOT NULL,
2617 `updated` int(11) NOT NULL,
2618 `name` varchar(255) NOT NULL,
2619 `description` varchar(255) NOT NULL,
2620 `code` varchar(255) NOT NULL,
2621 `external_code` varchar(255) NOT NULL,
2622 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2623
2624 CREATE TABLE IF NOT EXISTS `{$this->employeesTable}` (
2625 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
2626 `employee_id` varchar(255) NOT NULL,
2627 `owner_id` varchar(255) NOT NULL,
2628 `group_id` varchar(255) NOT NULL,
2629 `shared` varchar(255) NOT NULL,
2630 `version` varchar(255) NOT NULL,
2631 `updated` varchar(255) NOT NULL,
2632 `external_code` varchar(255) NOT NULL,
2633 `archived` varchar(255) NOT NULL,
2634 `created` varchar(255) NOT NULL,
2635 `uid` varchar(255) NOT NULL,
2636 `email` varchar(255) NOT NULL,
2637 `phone` varchar(255) NOT NULL,
2638 `full_name` varchar(255) NOT NULL,
2639 `short_fio` varchar(255) NOT NULL,
2640 `cashier_id` varchar(255) NOT NULL,
2641 `retail_store_id` varchar(255) NOT NULL
2642 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2643
2644 CREATE TABLE IF NOT EXISTS `{$this->storesTable}` (
2645 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
2646 `store_id` varchar(255) NOT NULL,
2647 `owner_id` text NOT NULL,
2648 `shared` text NOT NULL,
2649 `group_id` text NOT NULL,
2650 `version` text NOT NULL,
2651 `updated` text NOT NULL,
2652 `name` text NOT NULL,
2653 `description` text NOT NULL,
2654 `code` text NOT NULL,
2655 `external_code` text NOT NULL,
2656 `archived` varchar(255) NOT NULL,
2657 `address` varchar(255) NOT NULL,
2658 `parent` varchar(255) NOT NULL,
2659 `path_name` varchar(255) NOT NULL
2660 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2661
2662 CREATE TABLE IF NOT EXISTS `{$this->organizationsTable}` (
2663 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
2664 `organisation_id` varchar(255) NOT NULL,
2665 `owner_id` varchar(255) NOT NULL,
2666 `shared` varchar(255) NOT NULL,
2667 `group_id` varchar(255) NOT NULL,
2668 `version` varchar(255) NOT NULL,
2669 `updated` varchar(255) NOT NULL,
2670 `name` varchar(255) NOT NULL,
2671 `description` varchar(255) NOT NULL,
2672 `code` varchar(255) NOT NULL,
2673 `external_code` varchar(255) NOT NULL,
2674 `archived` varchar(255) NOT NULL,
2675 `created` varchar(255) NOT NULL,
2676 `company_type` varchar(255) NOT NULL,
2677 `legal_title` varchar(255) NOT NULL,
2678 `legal_address` varchar(255) NOT NULL,
2679 `inn` varchar(255) NOT NULL,
2680 `kpp` varchar(255) NOT NULL,
2681 `ogrn` varchar(255) NOT NULL,
2682 `ogrnip` varchar(255) NOT NULL,
2683 `okpo` varchar(255) NOT NULL,
2684 `certificate_number` varchar(255) NOT NULL,
2685 `certificate_date` varchar(255) NOT NULL,
2686 `email` varchar(255) NOT NULL,
2687 `phone` varchar(255) NOT NULL,
2688 `fax` varchar(255) NOT NULL,
2689 `is_egais_enable` varchar(255) NOT NULL,
2690 `fsrar_id` varchar(255) NOT NULL,
2691 `payer_vat` varchar(255) NOT NULL,
2692 `utm_url` varchar(255) NOT NULL,
2693 `actual_address` varchar(255) NOT NULL,
2694 `director` varchar(255) NOT NULL,
2695 `chief_accountant` varchar(255) NOT NULL
2696 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2697
2698 CREATE TABLE IF NOT EXISTS `{$this->accountsTable}` (
2699 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
2700 `account_id` varchar(255) NOT NULL,
2701 `organisation_id` varchar(255) NOT NULL,
2702 `version` text NOT NULL,
2703 `updated` varchar(255) NOT NULL,
2704 `is_default` varchar(255) NOT NULL,
2705 `account_number` varchar(255) NOT NULL,
2706 `bank_name` varchar(255) NOT NULL,
2707 `bank_location` varchar(255) NOT NULL,
2708 `correspondent_account` varchar(255) NOT NULL,
2709 `bic` varchar(255) NOT NULL,
2710 `agent_id` varchar(255) NOT NULL
2711 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2712
2713 CREATE TABLE IF NOT EXISTS `{$this->retailStoreTable}` (
2714 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
2715 `login` varchar(255) NOT NULL,
2716 `retail_store_id` text NOT NULL,
2717 `updated` varchar(255) NOT NULL,
2718 `name` varchar(255) NOT NULL,
2719 `discount_max_percent` varchar(255) NOT NULL,
2720 `price_type` varchar(255) NOT NULL,
2721 `owner_name` varchar(255) NOT NULL,
2722 `owner_email` varchar(255) NOT NULL,
2723 `owner_phone` varchar(255) NOT NULL
2724 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2725
2726 CREATE TABLE IF NOT EXISTS `{$this->customerOrdersTable}` (
2727 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
2728 `customer_order_id` varchar(255) NOT NULL,
2729 `owner_id` varchar(255) NOT NULL,
2730 `version` varchar(255) NOT NULL,
2731 `updated` varchar(255) NOT NULL,
2732 `deleted` varchar(255) NOT NULL,
2733 `name` varchar(255) NOT NULL,
2734 `description` varchar(255) NOT NULL,
2735 `external_code` varchar(255) NOT NULL,
2736 `moment` varchar(255) NOT NULL,
2737 `applicable` varchar(255) NOT NULL,
2738 `vat_enabled` varchar(255) NOT NULL,
2739 `sum` varchar(255) NOT NULL,
2740 `rate` varchar(255) NOT NULL,
2741 `shared` varchar(255) NOT NULL,
2742 `group_id` varchar(255) NOT NULL,
2743 `organization_id` varchar(255) NOT NULL,
2744 `agent_id` varchar(255) NOT NULL,
2745 `store_id` varchar(255) NOT NULL,
2746 `created` varchar(255) NOT NULL,
2747 `vat_sum` varchar(255) NOT NULL,
2748 `reserved_sum` varchar(255) NOT NULL,
2749 `delivery_planned_moment` varchar(255) NOT NULL,
2750 `payed_sum` varchar(255) NOT NULL,
2751 `shipped_sum` varchar(255) NOT NULL,
2752 `invoiced_sum` varchar(255) NOT NULL,
2753 `project_id` varchar(255) NOT NULL
2754 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2755
2756 CREATE TABLE IF NOT EXISTS `{$this->purchaseOrderTable}` (
2757 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
2758 `purchase_order_id` varchar(255) NOT NULL,
2759 `owner_id` varchar(255) NOT NULL,
2760 `version` varchar(255) NOT NULL,
2761 `updated` varchar(255) NOT NULL,
2762 `deleted` varchar(255) NOT NULL,
2763 `name` varchar(255) NOT NULL,
2764 `description` varchar(255) NOT NULL,
2765 `external_code` varchar(255) NOT NULL,
2766 `moment` varchar(255) NOT NULL,
2767 `applicable` varchar(255) NOT NULL,
2768 `vat_enabled` varchar(255) NOT NULL,
2769 `sum` varchar(255) NOT NULL,
2770 `rate` varchar(255) NOT NULL,
2771 `shared` varchar(255) NOT NULL,
2772 `group_id` varchar(255) NOT NULL,
2773 `organization_id` varchar(255) NOT NULL,
2774 `agent_id` varchar(255) NOT NULL,
2775 `store_id` varchar(255) NOT NULL,
2776 `created` varchar(255) NOT NULL,
2777 `vat_sum` varchar(255) NOT NULL,
2778 `reserved_sum` varchar(255) NOT NULL,
2779 `delivery_planned_moment` varchar(255) NOT NULL,
2780 `payed_sum` varchar(255) NOT NULL,
2781 `shipped_sum` varchar(255) NOT NULL,
2782 `invoiced_sum` varchar(255) NOT NULL,
2783 `project_id` varchar(255) NOT NULL,
2784 `wait_sum` varchar(255) NOT NULL
2785 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2786
2787 CREATE TABLE IF NOT EXISTS `{$this->invoiceOutTable}` (
2788 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
2789 `invoice_out_id` varchar(255) NOT NULL,
2790 `owner_id` varchar(255) NOT NULL,
2791 `shared` text NOT NULL,
2792 `group_id` varchar(255) NOT NULL,
2793 `version` varchar(255) NOT NULL,
2794 `updated` varchar(255) NOT NULL,
2795 `name` varchar(255) NOT NULL,
2796 `external_code` varchar(255) NOT NULL,
2797 `moment` varchar(255) NOT NULL,
2798 `applicable` varchar(255) NOT NULL,
2799 `rate` varchar(255) NOT NULL,
2800 `sum` varchar(255) NOT NULL,
2801 `store_id` varchar(255) NOT NULL,
2802 `agent_id` varchar(255) NOT NULL,
2803 `organization_id` varchar(255) NOT NULL,
2804 `created` varchar(255) NOT NULL,
2805 `vat_enabled` varchar(255) NOT NULL,
2806 `vat_sum` varchar(255) NOT NULL,
2807 `payment_planned_moment` varchar(255) NOT NULL,
2808 `payed_sum` varchar(255) NOT NULL,
2809 `shipped_sum` varchar(255) NOT NULL,
2810 `project_id` varchar(255) NOT NULL,
2811 `customer_order_id` varchar(255) NOT NULL
2812 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2813
2814 CREATE TABLE IF NOT EXISTS `{$this->invoiceInTable}` (
2815 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
2816 `invoice_out_id` varchar(255) NOT NULL,
2817 `owner_id` varchar(255) NOT NULL,
2818 `shared` text NOT NULL,
2819 `group_id` varchar(255) NOT NULL,
2820 `version` varchar(255) NOT NULL,
2821 `updated` varchar(255) NOT NULL,
2822 `name` varchar(255) NOT NULL,
2823 `external_code` varchar(255) NOT NULL,
2824 `moment` varchar(255) NOT NULL,
2825 `applicable` varchar(255) NOT NULL,
2826 `rate` varchar(255) NOT NULL,
2827 `sum` varchar(255) NOT NULL,
2828 `store_id` varchar(255) NOT NULL,
2829 `agent_id` varchar(255) NOT NULL,
2830 `organization_id` varchar(255) NOT NULL,
2831 `created` varchar(255) NOT NULL,
2832 `vat_enabled` varchar(255) NOT NULL,
2833 `vat_sum` varchar(255) NOT NULL,
2834 `payment_planned_moment` varchar(255) NOT NULL,
2835 `payed_sum` varchar(255) NOT NULL,
2836 `shipped_sum` varchar(255) NOT NULL,
2837 `project_id` varchar(255) NOT NULL,
2838 `incoming_number` varchar(255) NOT NULL,
2839 `incoming_date` varchar(255) NOT NULL
2840 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2841
2842 CREATE TABLE IF NOT EXISTS `{$this->positionsInvoicesArrayTable}` (
2843 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
2844 `positions_array_id` varchar(255) NOT NULL,
2845 `position_id` text NOT NULL
2846 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2847
2848 CREATE TABLE IF NOT EXISTS `{$this->positionsInvoicesTable}` (
2849 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
2850 `position_id` varchar(255) NOT NULL,
2851 `quantity` text NOT NULL,
2852 `price` text NOT NULL,
2853 `discount` text NOT NULL,
2854 `vat` text NOT NULL,
2855 `assortment_id` text NOT NULL
2856 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2857
2858 CREATE TABLE IF NOT EXISTS `{$this->positionsOrdersArrayTable}` (
2859 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
2860 `positions_array_id` varchar(255) NOT NULL,
2861 `position_id` text NOT NULL
2862 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2863
2864 CREATE TABLE IF NOT EXISTS `{$this->positionsOrdersTable}` (
2865 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
2866 `position_id` varchar(255) NOT NULL,
2867 `quantity` text NOT NULL,
2868 `price` text NOT NULL,
2869 `discount` text NOT NULL,
2870 `vat` text NOT NULL,
2871 `assortment_id` text NOT NULL
2872 `shipped` text NOT NULL,
2873 `reserve` text NOT NULL,
2874 `wait` text NOT NULL
2875 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2876
2877 CREATE TABLE IF NOT EXISTS `{$this->positionsDemandsArrayTable}` (
2878 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
2879 `positions_array_id` varchar(255) NOT NULL,
2880 `position_id` text NOT NULL
2881 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2882
2883 CREATE TABLE IF NOT EXISTS `{$this->positionsDemandTable}` (
2884 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
2885 `position_id` varchar(255) NOT NULL,
2886 `quantity` text NOT NULL,
2887 `price` text NOT NULL,
2888 `discount` text NOT NULL,
2889 `vat` text NOT NULL,
2890 `assortment_id` text NOT NULL,
2891 `cost` text NOT NULL
2892 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2893
2894 CREATE TABLE IF NOT EXISTS `{$this->positionsSuppliesArrayTable}` (
2895 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
2896 `positions_array_id` varchar(255) NOT NULL,
2897 `position_id` text NOT NULL
2898 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2899
2900 CREATE TABLE IF NOT EXISTS `{$this->positionsSupplyTable}` (
2901 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
2902 `position_id` varchar(255) NOT NULL,
2903 `quantity` text NOT NULL,
2904 `price` text NOT NULL,
2905 `discount` text NOT NULL,
2906 `vat` text NOT NULL,
2907 `assortment_id` text NOT NULL,
2908 `gtd` text NOT NULL,
2909 `country_id` text NOT NULL
2910 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2911
2912 CREATE TABLE IF NOT EXISTS `{$this->paymentInTable}` (
2913 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
2914 `payment_in_id` varchar(255) NOT NULL,
2915 `version` text NOT NULL,
2916 `updated` varchar(255) NOT NULL,
2917 `deleted` varchar(255) NOT NULL,
2918 `name` varchar(255) NOT NULL,
2919 `description` varchar(255) NOT NULL,
2920 `external_code` varchar(255) NOT NULL,
2921 `moment` varchar(255) NOT NULL,
2922 `applicable` varchar(255) NOT NULL,
2923 `sum` varchar(255) NOT NULL,
2924 `rate` varchar(255) NOT NULL,
2925 `owner_id` varchar(255) NOT NULL,
2926 `shared` varchar(255) NOT NULL,
2927 `group_id` varchar(255) NOT NULL,
2928 `organization_id` varchar(255) NOT NULL,
2929 `agent_id` varchar(255) NOT NULL,
2930 `created` varchar(255) NOT NULL,
2931 `payment_purpose` varchar(255) NOT NULL,
2932 `vat_sum` varchar(255) NOT NULL,
2933 `incoming_date` varchar(255) NOT NULL,
2934 `incoming_number` varchar(255) NOT NULL
2935 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2936
2937 CREATE TABLE IF NOT EXISTS `{$this->paymentOutTable}` (
2938 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
2939 `payment_in_id` varchar(255) NOT NULL,
2940 `version` text NOT NULL,
2941 `updated` varchar(255) NOT NULL,
2942 `deleted` varchar(255) NOT NULL,
2943 `name` varchar(255) NOT NULL,
2944 `description` varchar(255) NOT NULL,
2945 `external_code` varchar(255) NOT NULL,
2946 `moment` varchar(255) NOT NULL,
2947 `applicable` varchar(255) NOT NULL,
2948 `sum` varchar(255) NOT NULL,
2949 `rate` varchar(255) NOT NULL,
2950 `owner_id` varchar(255) NOT NULL,
2951 `shared` varchar(255) NOT NULL,
2952 `group_id` varchar(255) NOT NULL,
2953 `organization_id` varchar(255) NOT NULL,
2954 `agent_id` varchar(255) NOT NULL,
2955 `created` varchar(255) NOT NULL,
2956 `payment_purpose` varchar(255) NOT NULL,
2957 `vat_sum` varchar(255) NOT NULL,
2958 `expense_item_id` varchar(255) NOT NULL
2959 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2960
2961 CREATE TABLE IF NOT EXISTS `{$this->cashInTable}` (
2962 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
2963 `login` varchar(255) NOT NULL,
2964 `cash_in_id` varchar(255) NOT NULL,
2965 `name` varchar(255) NOT NULL,
2966 `sum` varchar(255) NOT NULL,
2967 `owner_name` varchar(255) NOT NULL,
2968 `owner_email` varchar(255) NOT NULL,
2969 `owner_phone` varchar(255) NOT NULL,
2970 `owner_sum` varchar(255) NOT NULL,
2971 `owner_vat_sum` varchar(255) NOT NULL,
2972 `group_name` varchar(255) NOT NULL,
2973 `agency_name` varchar(255) NOT NULL,
2974 `agency_legal_title` varchar(255) NOT NULL,
2975 `agency_legal_address` varchar(255) NOT NULL,
2976 `agency_inn` varchar(255) NOT NULL,
2977 `agency_kpp` varchar(255) NOT NULL,
2978 `agency_sales_amount` varchar(255) NOT NULL
2979 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
2980
2981 CREATE TABLE IF NOT EXISTS `{$this->demandTable}` (
2982 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
2983 `demand_id` varchar(255) NOT NULL,
2984 `owner_id` varchar(255) NOT NULL,
2985 `shared` varchar(255) NOT NULL,
2986 `group_id` varchar(255) NOT NULL,
2987 `version` varchar(255) NOT NULL,
2988 `updated` varchar(255) NOT NULL,
2989 `name` varchar(255) NOT NULL,
2990 `description` varchar(255) NOT NULL,
2991 `external_code` varchar(255) NOT NULL,
2992 `moment` varchar(255) NOT NULL,
2993 `applicable` varchar(255) NOT NULL,
2994 `vat_enabled` varchar(255) NOT NULL,
2995 `rate` varchar(255) NOT NULL,
2996 `sum` varchar(255) NOT NULL,
2997 `store_id` varchar(255) NOT NULL,
2998 `agent_id` varchar(255) NOT NULL,
2999 `organization_id` varchar(255) NOT NULL,
3000 `created` varchar(255) NOT NULL
3001 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3002
3003 CREATE TABLE IF NOT EXISTS `{$this->supplyTable}` (
3004 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
3005 `demand_id` varchar(255) NOT NULL,
3006 `owner_id` varchar(255) NOT NULL,
3007 `shared` varchar(255) NOT NULL,
3008 `group_id` varchar(255) NOT NULL,
3009 `version` varchar(255) NOT NULL,
3010 `updated` varchar(255) NOT NULL,
3011 `name` varchar(255) NOT NULL,
3012 `description` varchar(255) NOT NULL,
3013 `external_code` varchar(255) NOT NULL,
3014 `moment` varchar(255) NOT NULL,
3015 `applicable` varchar(255) NOT NULL,
3016 `vat_enabled` varchar(255) NOT NULL,
3017 `rate` varchar(255) NOT NULL,
3018 `sum` varchar(255) NOT NULL,
3019 `store_id` varchar(255) NOT NULL,
3020 `agent_id` varchar(255) NOT NULL,
3021 `organization_id` varchar(255) NOT NULL,
3022 `created` varchar(255) NOT NULL
3023 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3024
3025 CREATE TABLE IF NOT EXISTS `{$this->lossTable}` (
3026 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
3027 `loss_id` varchar(255) NOT NULL,
3028 `created` varchar(255) NOT NULL,
3029 `name` varchar(255) NOT NULL,
3030 `owner_name` varchar(255) NOT NULL,
3031 `owner_email` varchar(255) NOT NULL,
3032 `owner_phone` varchar(255) NOT NULL,
3033 `owner_sum` varchar(255) NOT NULL,
3034 `owner_vat_sum` varchar(255) NOT NULL,
3035 `group_name` varchar(255) NOT NULL,
3036 `store_name` varchar(255) NOT NULL,
3037 `position_quantity` varchar(255) NOT NULL,
3038 `position_price` varchar(255) NOT NULL,
3039 `position_discount` varchar(255) NOT NULL
3040 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3041
3042 CREATE TABLE IF NOT EXISTS `{$this->moveTable}` (
3043 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
3044 `login` varchar(255) NOT NULL,
3045 `move_id` varchar(255) NOT NULL,
3046 `name` varchar(255) NOT NULL,
3047 `sum` varchar(255) NOT NULL,
3048 `owner_name` varchar(255) NOT NULL,
3049 `owner_email` varchar(255) NOT NULL,
3050 `owner_phone` varchar(255) NOT NULL,
3051 `owner_sum` varchar(255) NOT NULL,
3052 `owner_vat_sum` varchar(255) NOT NULL,
3053 `group_name` varchar(255) NOT NULL,
3054 `position_quantity` varchar(255) NOT NULL,
3055 `position_price` varchar(255) NOT NULL,
3056 `position_discount` varchar(255) NOT NULL,
3057 `source_store_name` text NOT NULL,
3058 `target_store_name` varchar(255) NOT NULL
3059 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3060
3061 CREATE TABLE IF NOT EXISTS `{$this->factureOutTable}` (
3062 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
3063 `login` varchar(255) NOT NULL,
3064 `facture_out_id` text NOT NULL,
3065 `name` text NOT NULL,
3066 `sum` text NOT NULL,
3067 `owner_name` text NOT NULL,
3068 `owner_email` text NOT NULL,
3069 `owner_phone` text NOT NULL,
3070 `owner_sum` text NOT NULL,
3071 `owner_vat_sum` text NOT NULL,
3072 `group_name` text NOT NULL,
3073 `agency_name` text NOT NULL,
3074 `agency_legal_title` text NOT NULL,
3075 `agency_legal_address` text NOT NULL,
3076 `agency_inn` text NOT NULL,
3077 `agency_kpp` text NOT NULL,
3078 `agency_sales_amount` text NOT NULL,
3079 `position_quantity` text NOT NULL,
3080 `position_price` text NOT NULL,
3081 `position_discount` text NOT NULL,
3082 `source_store_name` text NOT NULL,
3083 `target_store_name` varchar(255) NOT NULL
3084 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3085
3086 CREATE TABLE IF NOT EXISTS `{$this->inventoryTable}` (
3087 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
3088 `login` varchar(255) NOT NULL,
3089 `inventory_id` text NOT NULL,
3090 `name` varchar(255) NOT NULL,
3091 `sum` varchar(255) NOT NULL,
3092 `owner_name` varchar(255) NOT NULL,
3093 `owner_email` varchar(255) NOT NULL,
3094 `owner_phone` varchar(255) NOT NULL,
3095 `owner_sum` varchar(255) NOT NULL,
3096 `owner_vat_sum` varchar(255) NOT NULL,
3097 `group_name` varchar(255) NOT NULL,
3098 `store_name` varchar(255) NOT NULL,
3099 `position_quantity` varchar(255) NOT NULL,
3100 `position_price` varchar(255) NOT NULL,
3101 `position_discount` varchar(255) NOT NULL
3102 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3103
3104 CREATE TABLE IF NOT EXISTS `{$this->processingPlanTable}` (
3105 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
3106 `login` varchar(255) NOT NULL,
3107 `processing_plan_id` text NOT NULL,
3108 `name` text NOT NULL,
3109 `cost` text NOT NULL,
3110 `owner_name` text NOT NULL,
3111 `owner_email` text NOT NULL,
3112 `owner_phone` text NOT NULL,
3113 `owner_sum` text NOT NULL,
3114 `owner_vat_sum` text NOT NULL,
3115 `owner_payed_sum` text NOT NULL,
3116 `group_name` text NOT NULL,
3117 `material_quantity` text NOT NULL,
3118 `product_name` varchar(255) NOT NULL,
3119 `product_min_price` varchar(255) NOT NULL
3120 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3121
3122 CREATE TABLE IF NOT EXISTS `{$this->processingOrderTable}` (
3123 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
3124 `login` varchar(255) NOT NULL,
3125 `processing_order_id` text NOT NULL,
3126 `name` text NOT NULL,
3127 `quantity` text NOT NULL,
3128 `owner_name` text NOT NULL,
3129 `owner_email` text NOT NULL,
3130 `owner_phone` varchar(255) NOT NULL,
3131 `owner_sum` varchar(255) NOT NULL,
3132 `owner_vat_sum` varchar(255) NOT NULL,
3133 `group_name` varchar(255) NOT NULL
3134 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3135
3136 CREATE TABLE IF NOT EXISTS `{$this->auditTable}` (
3137 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
3138 `login` varchar(255) NOT NULL,
3139 `audit_id` text NOT NULL,
3140 `uid` varchar(255) NOT NULL
3141 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3142
3143 CREATE TABLE IF NOT EXISTS `{$this->stockAllTable}` (
3144 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
3145 `login` varchar(255) NOT NULL,
3146 `stock` text NOT NULL,
3147 `in_transit` varchar(255) NOT NULL,
3148 `reserve` varchar(255) NOT NULL,
3149 `quantity` varchar(255) NOT NULL,
3150 `name` varchar(255) NOT NULL,
3151 `code` varchar(255) NOT NULL,
3152 `price` varchar(255) NOT NULL,
3153 `sale_price` varchar(255) NOT NULL
3154 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3155
3156 CREATE TABLE IF NOT EXISTS `{$this->salePricesTable}` (
3157 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
3158 `assortment_id` varchar(255) NOT NULL,
3159 `value` text NOT NULL,
3160 `currency_code` varchar(255) NOT NULL,
3161 `price_type` varchar(255) NOT NULL
3162 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3163
3164 CREATE TABLE IF NOT EXISTS `{$this->barcodesTable}` (
3165 `id` int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
3166 `assortment_id` varchar(255) NOT NULL,
3167 `barcode` text NOT NULL
3168 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
3169
3170 ";
3171
3172 $this->makeYiiOperation($sql);
3173
3174 return true;
3175 }
3176
3177 private function dropTable()
3178 {
3179 $sql = "
3180 DROP TABLE IF EXISTS `{$this->counterPartyTable}`;
3181 DROP TABLE IF EXISTS `{$this->assortmentTable}`;
3182 DROP TABLE IF EXISTS `{$this->currencyTable}`;
3183 DROP TABLE IF EXISTS `{$this->productTable}`;
3184 DROP TABLE IF EXISTS `{$this->serviceTable}`;
3185 DROP TABLE IF EXISTS `{$this->bundleTable}`;
3186 DROP TABLE IF EXISTS `{$this->productFolderTable}`;
3187 DROP TABLE IF EXISTS `{$this->variantTable}`;
3188 DROP TABLE IF EXISTS `{$this->consignmentTable}`;
3189 DROP TABLE IF EXISTS `{$this->contractTable}`;
3190 DROP TABLE IF EXISTS `{$this->projectTable}`;
3191 DROP TABLE IF EXISTS `{$this->expenseItemTable}`;
3192 DROP TABLE IF EXISTS `{$this->countriesTable}`;
3193 DROP TABLE IF EXISTS `{$this->groupsTable}`;
3194 DROP TABLE IF EXISTS `{$this->discountTable}`;
3195 DROP TABLE IF EXISTS `{$this->uomTable}`;
3196 DROP TABLE IF EXISTS `{$this->employeesTable}`;
3197 DROP TABLE IF EXISTS `{$this->storesTable}`;
3198 DROP TABLE IF EXISTS `{$this->organizationsTable}`;
3199 DROP TABLE IF EXISTS `{$this->accountsTable}`;
3200 DROP TABLE IF EXISTS `{$this->retailStoreTable}`;
3201 DROP TABLE IF EXISTS `{$this->cashiersTable}`;
3202 DROP TABLE IF EXISTS `{$this->taskTable}`;
3203 DROP TABLE IF EXISTS `{$this->retailshiftTable}`;
3204 DROP TABLE IF EXISTS `{$this->enterTable}`;
3205 DROP TABLE IF EXISTS `{$this->customerOrdersTable}`;
3206 DROP TABLE IF EXISTS `{$this->purchaseOrderTable}`;
3207 DROP TABLE IF EXISTS `{$this->invoiceOutTable}`;
3208 DROP TABLE IF EXISTS `{$this->invoiceInTable}`;
3209 DROP TABLE IF EXISTS `{$this->paymentInTable}`;
3210 DROP TABLE IF EXISTS `{$this->paymentOutTable}`;
3211 DROP TABLE IF EXISTS `{$this->cashInTable}`;
3212 DROP TABLE IF EXISTS `{$this->cashOutTable}`;
3213 DROP TABLE IF EXISTS `{$this->demandTable}`;
3214 DROP TABLE IF EXISTS `{$this->supplyTable}`;
3215 DROP TABLE IF EXISTS `{$this->lossTable}`;
3216 DROP TABLE IF EXISTS `{$this->moveTable}`;
3217 DROP TABLE IF EXISTS `{$this->retailDemandTable}`;
3218 DROP TABLE IF EXISTS `{$this->retailSalesReturnTable}`;
3219 DROP TABLE IF EXISTS `{$this->retailDrawerCashInTable}`;
3220 DROP TABLE IF EXISTS `{$this->retailDrawerCashOutTable}`;
3221 DROP TABLE IF EXISTS `{$this->salesReturnTable}`;
3222 DROP TABLE IF EXISTS `{$this->purchaseReturnTable}`;
3223 DROP TABLE IF EXISTS `{$this->factureOutTable}`;
3224 DROP TABLE IF EXISTS `{$this->factureInTable}`;
3225 DROP TABLE IF EXISTS `{$this->inventoryTable}`;
3226 DROP TABLE IF EXISTS `{$this->commissionReportInTable}`;
3227 DROP TABLE IF EXISTS `{$this->commissionReportOutTable}`;
3228 DROP TABLE IF EXISTS `{$this->pricelistTable}`;
3229 DROP TABLE IF EXISTS `{$this->commissionReportOutTable}`;
3230 DROP TABLE IF EXISTS `{$this->processingPlanTable}`;
3231 DROP TABLE IF EXISTS `{$this->processingOrderTable}`;
3232 DROP TABLE IF EXISTS `{$this->processingTable}`;
3233 DROP TABLE IF EXISTS `{$this->internalOrderTable}`;
3234 DROP TABLE IF EXISTS `{$this->stockAllTable}`;
3235 DROP TABLE IF EXISTS `{$this->stockByStoreTable}`;
3236 DROP TABLE IF EXISTS `{$this->reportDashboardDayTable}`;
3237 DROP TABLE IF EXISTS `{$this->reportDashboardWeekTable}`;
3238 DROP TABLE IF EXISTS `{$this->reportDashboardMonthTable}`;
3239 DROP TABLE IF EXISTS `{$this->auditTable}`;
3240 DROP TABLE IF EXISTS `{$this->salePricesTable}`;
3241 DROP TABLE IF EXISTS `{$this->barcodesTable}`;
3242 DROP TABLE IF EXISTS `{$this->positionsInvoicesTable}`;
3243 DROP TABLE IF EXISTS `{$this->positionsInvoicesArrayTable}`;
3244 DROP TABLE IF EXISTS `{$this->positionsOrdersArrayTable}`;
3245 DROP TABLE IF EXISTS `{$this->positionsOrdersTable}`;
3246 DROP TABLE IF EXISTS `{$this->positionsDemandsArrayTable}`;
3247 DROP TABLE IF EXISTS `{$this->positionsDemandTable}`;
3248 DROP TABLE IF EXISTS `{$this->positionsSuppliesArrayTable}`;
3249 DROP TABLE IF EXISTS `{$this->positionsSupplyTable}`;
3250 ";
3251
3252 $this->makeYiiOperation($sql);
3253
3254 return true;
3255 }
3256}