Advertisement
Guest User

Untitled

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