Skip to content

Commit

Permalink
14. add one_c_id field
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrakovich committed Jun 1, 2024
1 parent aeee8fa commit c2c3684
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 15 deletions.
11 changes: 4 additions & 7 deletions src/app/Jobs/OneC/UpdateOfflineOrdersJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ class UpdateOfflineOrdersJob extends AbstractJob
*/
public function handle(): void
{
$latestCode = $this->getLatestCode();
$orders = $this->getNewOrders($latestCode);
$orders = $this->getNewOrders();
$returnOrders = $this->getOrdersForReturn($orders);

foreach ($orders as $order) {
Expand Down Expand Up @@ -75,21 +74,19 @@ public function handle(): void
*/
private function getLatestCode(): int
{
$receiptNumber = OfflineOrder::query()->latest('id')->value('receipt_number');

return OfflineOrder1C::getLatestCodeByReceiptNumber($receiptNumber);
return OfflineOrder::query()->latest('id')->value('one_c_id');
}

/**
* Get new offline orders based on the latest code.
*
* @return Collection|OfflineOrder1C[]
*/
private function getNewOrders(int $latestCode): Collection
private function getNewOrders(): Collection
{
return OfflineOrder1C::query()
->with(['stock', 'product', 'size'])
->where('CODE', '>', $latestCode)
->where('CODE', '>', $this->getLatestCode())
->limit(self::NEW_ORDERS_LIMIT)
->orderBy('CODE')
->get();
Expand Down
8 changes: 0 additions & 8 deletions src/app/Models/OneC/OfflineOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,6 @@ class OfflineOrder extends AbstractOneCModel
'SP6101' => 'float',
];

/**
* Get the latest code by receipt number from the offline orders.
*/
public static function getLatestCodeByReceiptNumber(?string $receiptNumber): int
{
return (int)self::query()->where('SP6098', $receiptNumber)->value('CODE');
}

/**
* Check if the order is a return.
*/
Expand Down
1 change: 1 addition & 0 deletions src/app/Models/Orders/OfflineOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

/**
* @property int $id
* @property int $one_c_id CODE field from 1C DB
* @property string $receipt_number Receipt number
* @property int|null $stock_id
* @property int|null $product_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public function up(): void
Schema::table('offline_orders', function (Blueprint $table) {
$table->dropUnique(['receipt_number']);
$table->index(['receipt_number']);
$table->foreignId('one_c_id')->unique()->after('id')->comment('CODE field from 1C DB');
$table->foreignId('one_c_product_id')->index()->after('product_id')->comment('External product id from 1C');
});
}
Expand All @@ -26,6 +27,7 @@ public function down(): void
Schema::table('offline_orders', function (Blueprint $table) {
$table->dropIndex(['receipt_number']);
$table->unique(['receipt_number']);
$table->dropColumn('one_c_id');
$table->dropColumn('one_c_product_id');
});
}
Expand Down

0 comments on commit c2c3684

Please sign in to comment.