diff --git a/commands/OutOrders.php b/commands/OutOrders.php index de0d749..1936f5f 100644 --- a/commands/OutOrders.php +++ b/commands/OutOrders.php @@ -2,9 +2,9 @@ namespace App\Commands; +use App\Component\Models\ExchangeShifts; use App\Component\Models\OrderBot; use App\Component\Models\Report; -use App\Component\Models\Shifts; use App\Console\Commands\HRCCommand; use App\Console\Commands\HRCCommandInterface; @@ -13,7 +13,7 @@ class OutOrders extends HRCCommand implements HRCCommandInterface { public function command($input, $output = null) { if ((array_key_exists('shift_id', $input)) === true) { - $shifts = Shifts::select('id', 'opened', 'closed')->where('id', '=', $input['shift_id'])->get(); + $shifts = ExchangeShifts::select('id', 'opened', 'closed')->where('id', '=', $input['shift_id'])->get(); if (is_array($shifts) || is_object($shifts)) { foreach ($shifts as $shift) { $out = array('id' => $shift['id'], 'opened' => $shift['opened'], 'closed' => $shift['closed']); diff --git a/commands/POSTRestoreShift.php b/commands/POSTRestoreShift.php new file mode 100644 index 0000000..0c66ef5 --- /dev/null +++ b/commands/POSTRestoreShift.php @@ -0,0 +1,160 @@ +get(); + foreach ($terminal_updates_old as $key => $terminal_online) { + $old_date = date_create($terminal_online['next_at']); + date_modify($old_date, '+1 hour'); + $new_date = date_format($old_date, 'Y-m-d H:i:s'); + $new_terminal_online = TerminalUpdate::find($terminal_online['id']); + $new_terminal_online->next_at = $new_date; + $new_terminal_online->save(); + } + $terminal_updates_new = TerminalUpdate::where('method', '=', 'online')->get(); + + $exchange_shifts = ExchangeShifts::where('id', '=', $shift_id)->get(); + $exchange_orders = ExchangeOrders::where('shift_id', '=', $shift_id)->get(); + $exchange_items = ExchangeItems::where('shift_id', '=', $shift_id)->get(); + $exchange_actions = ExchangeActions::where('shift_id', '=', $shift_id)->get(); + $exchange_deleted = ExchangeDeleted::where('shift_id', '=', $shift_id)->get(); + + //clear shifts + Shifts::truncate(); + foreach ($exchange_shifts as $key => $exchange_shift) { + $shift = new Shifts; + $shift->opened = $exchange_shift['opened']; + $shift->closed = $exchange_shift['closed']; + $shift->who_open = $exchange_shift['who_open']; + $shift->who_close = $exchange_shift['who_close']; + $shift->z_number = $exchange_shift['id']; + $shift->save(); + } + //clear shift_online_orders + ShiftOnlineOrders::truncate(); + foreach ($exchange_orders as $key => $exchange_order) { + $shift_online_order = new ShiftOnlineOrders; + $shift_online_order->cash = $exchange_order["cash"]; + $shift_online_order->check_number = $exchange_order["check_number"]; + $shift_online_order->clearing = $exchange_order["clearing"]; + $shift_online_order->client_code = $exchange_order["client_code"]; + $shift_online_order->client_count = $exchange_order["clients_count"]; + if ($exchange_order["closed"] == '0000-00-00 00:00:00') { + $exchange_order["closed"] = '1970-01-01 00:00:00'; + } + $shift_online_order->closed = $exchange_order["closed"]; + $shift_online_order->code = $exchange_order["code"]; + $shift_online_order->credit = $exchange_order["credit"]; + $shift_online_order->full_sum = $exchange_order["full_sum"]; + $shift_online_order->guid = $exchange_order["guid"]; + $shift_online_order->is_block = $exchange_order["is_block"]; + $shift_online_order->is_closed = $exchange_order["is_closed"]; + $shift_online_order->is_deleted = $exchange_order["is_deleted"]; + $shift_online_order->is_edit = $exchange_order["is_edit"]; + $shift_online_order->is_printed = $exchange_order["is_printed"]; + $shift_online_order->is_returned = $exchange_order["is_returned"]; + $shift_online_order->is_self = $exchange_order["is_self"]; + $shift_online_order->is_waited = $exchange_order["is_waited"]; + if ($exchange_order["manual_discount"] == '') { + $exchange_order["manual_discount"] = 0; + } else { + $exchange_order["manual_discount"] = $exchange_order["manual_discount"] + 0; + } + $shift_online_order->manual_discount = $exchange_order["manual_discount"]; + $shift_online_order->opened = $exchange_order["opened"]; + $shift_online_order->order_sum = $exchange_order["order_sum"]; + $shift_online_order->params_code = $exchange_order["params_id"]; + $shift_online_order->place_name = $exchange_order["place_name"]; + $shift_online_order->presale = $exchange_order["presale"]; + $shift_online_order->sale_sum = $exchange_order["sale_sum"]; + $shift_online_order->self = $exchange_order["self"]; + $shift_online_order->table_name = $exchange_order["table_name"]; + $shift_online_order->table_place = $exchange_order["table_place"]; + $shift_online_order->terminal_id = $exchange_order["terminal_id"]; + $shift_online_order->version_type = $exchange_order["version_type"]; + $shift_online_order->who_close = $exchange_order["who_close"]; + $shift_online_order->who_open = $exchange_order["who_open"]; + $shift_online_order->save(); + } + + ShiftOnlineItems::truncate(); + foreach ($exchange_items as $key => $exchange_item) { + $shift_online_item = new ShiftOnlineItems; + $shift_online_item->code = $exchange_item["code"]; + $shift_online_item->cof = $exchange_item["cof"]; + $shift_online_item->count = $exchange_item["count"]; + $shift_online_item->count_real = $exchange_item["count_real"]; + $shift_online_item->count_return = $exchange_item["count_return"]; + $shift_online_item->dish_code = $exchange_item["dishes_code"]; + $shift_online_item->menu_code = $exchange_item["menu_code"]; + $shift_online_item->modificator_code = $exchange_item["modificator_code"]; + $shift_online_item->order_code = $exchange_item["order_code"]; + $shift_online_item->parent_id = $exchange_item["parent_id"]; + $shift_online_item->real_price = $exchange_item["real_price"]; + $shift_online_item->sale_price = $exchange_item["sale_price"]; + $shift_online_item->special_price = $exchange_item["special_price"]; + $shift_online_item->terminal_id = $exchange_item["terminal_id"]; + $shift_online_item->units_code = $exchange_item["units_id"]; + $shift_online_item->save(); + } + + ShiftOnlineActions::truncate(); + foreach ($exchange_actions as $key => $exchange_action) { + $shift_online_action = new ShiftOnlineActions; + $shift_online_action->type_action = $exchange_action["action_type"]; + $shift_online_action->more = $exchange_action["more"]; + $shift_online_action->order_code = $exchange_action["order_code"]; + $shift_online_action->order_position = $exchange_action["order_position"]; + $shift_online_action->reason = $exchange_action["reason"]; + $shift_online_action->terminal_id = $exchange_action["terminal_id"]; + $shift_online_action->time = $exchange_action["time"]; + $shift_online_action->value = $exchange_action["value"]; + $shift_online_action->who = $exchange_action["who"]; + $shift_online_action->workcode = $exchange_action["work_code"]; + $shift_online_action->workgroup = $exchange_action["work_group"]; + $shift_online_action->save(); + } + + ShiftOnlineDeleted::truncate(); + foreach ($exchange_deleted as $key => $exchange_deleted_item) { + $shift_online_deleted_item = new ShiftOnlineDeleted; + $shift_online_deleted_item->code = $exchange_deleted_item["code"]; + $shift_online_deleted_item->count = $exchange_deleted_item["count"]; + $shift_online_deleted_item->dishes_code = $exchange_deleted_item["dishes_code"]; + $shift_online_deleted_item->item_id = $exchange_deleted_item["item_id"]; + $shift_online_deleted_item->menu_code = $exchange_deleted_item["menu_code"]; + $shift_online_deleted_item->order_code = $exchange_deleted_item["order_code"]; + $shift_online_deleted_item->real_price = $exchange_deleted_item["real_price"]; + $shift_online_deleted_item->sale_price = $exchange_deleted_item["sale_price"]; + $shift_online_deleted_item->terminal_id = $exchange_deleted_item["terminal_id"]; + $shift_online_deleted_item->units_id = $exchange_deleted_item["units_id"]; + $shift_online_deleted_item->save(); + } + + return [ + 'status' => 'success', + 'terminal_old' => $terminal_updates_old, + 'terminal_new' => $terminal_updates_new, + ]; + } +} \ No newline at end of file diff --git a/database/migrations/2022_01_10_004227_add_columns_to_shift_online_orders.php b/database/migrations/2022_01_10_004227_add_columns_to_shift_online_orders.php new file mode 100644 index 0000000..6cd3587 --- /dev/null +++ b/database/migrations/2022_01_10_004227_add_columns_to_shift_online_orders.php @@ -0,0 +1,63 @@ +integer('is_self')->nullable(); + $table->integer('is_block')->nullable(); + $table->integer('is_edit')->nullable(); + $table->string('guid')->nullable(); + }); + Schema::table('shift_online_items', function (Blueprint $table) { + $table->decimal('count_real', $precision = 16, $scale = 2)->nullable(); + $table->decimal('count_return', $precision = 16, $scale = 2)->nullable(); + $table->integer('parent_id')->nullable(); + }); + Schema::table('shift_online_actions', function (Blueprint $table) { + $table->integer('terminal_id')->nullable(); + }); + Schema::table('exchange_orders', function (Blueprint $table) { + $table->string('table_place')->nullable(); + }); + Schema::table('exchange_items', function (Blueprint $table) { + $table->integer('modificator_code')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() { + Schema::table('shift_online_orders', function (Blueprint $table) { + $table->dropColumn('is_self'); + $table->dropColumn('guid'); + $table->dropColumn('is_block'); + $table->dropColumn('is_edit'); + }); + Schema::table('shift_online_items', function (Blueprint $table) { + $table->dropColumn('count_real'); + $table->dropColumn('count_return'); + $table->dropColumn('parent_id'); + }); + Schema::table('shift_online_actions', function (Blueprint $table) { + $table->dropColumn('terminal_id'); + }); + Schema::table('exchange_orders', function (Blueprint $table) { + $table->dropColumn('table_place'); + }); + Schema::table('exchange_items', function (Blueprint $table) { + $table->dropColumn('modificator_code'); + }); + } +} diff --git a/models/ExchangeActions.php b/models/ExchangeActions.php new file mode 100644 index 0000000..30a9388 --- /dev/null +++ b/models/ExchangeActions.php @@ -0,0 +1,9 @@ +