diff --git a/commands/ClientGroup.php b/commands/ClientGroup.php deleted file mode 100644 index 2759143..0000000 --- a/commands/ClientGroup.php +++ /dev/null @@ -1,55 +0,0 @@ -count() == 0) { - $group = new ClientsGroup; - $group->code = '0'; - $group->name = 'Без группы'; - $group->save(); - } - $client_groups = ClientsGroup::orderBy('code')->get(); - foreach ($client_groups as $client_group) { - $out[] = array('id' => $client_group['id'], 'name' => $client_group['name']); - } - $terminal = Terminal::where('soft', '=', 1)->where('is_active', '=', 1)->where('work_code', '=', 1)->first(); - $dir = __DIR__ . "/../../../Exchange/" . $terminal['key'] . "/"; - if (!is_dir($dir)) { - mkdir($dir, 0755, 'w+'); - } - - $files = glob($dir . "*.*"); - if (count($files) > 0) { - usort($files, function ($a, $b) { - return filemtime($a) < filemtime($b); - }); - - foreach ($files as $plk2) { - $file_array[] = str_replace($dir, '', $plk2); - } - $filename = $file_array['0']; - $file = date("d.m.Y H:i:s", filemtime(__DIR__ . "/../../../Exchange/" . $terminal['key'] . "/" . $file_array['0'])); - } else { - $file_array = ''; - $filename = ''; - $file = ''; - } - return [ - 'status' => 'success', - 'groups' => $out, - 'terminalKey' => $terminal['key'], - 'files' => $files, - 'filename' => $filename, - 'filedate' => $file, - ]; - } -} \ No newline at end of file diff --git a/commands/Clients.php b/commands/Clients.php deleted file mode 100644 index ec40e32..0000000 --- a/commands/Clients.php +++ /dev/null @@ -1,56 +0,0 @@ -count() == 0) { - $group = new ClientsGroup([ - 'code' => '0', - 'name' => 'Без группы', - ]); - $group->save(); - } - $countPerPage = 25; - $offset = ($input['page'] - 1) * $countPerPage; - if ($input['group_id'] == 0) { - $group = ClientsGroup::where('code', '=', $input['group_id'])->first(); - } else { - $group = ClientsGroup::where('id', '=', $input['group_id'])->first(); - } - $clients = Client::where('group_id', '=', $group['code'])->skip($offset)->take($countPerPage)->get(); - $total = Client::where('group_id', '=', $group['code'])->count(); - if ($total == NULL) { - return [ - 'status' => 'success', - 'clients' => array(), - 'total' => 0, - 'size' => $countPerPage, - 'pages' => 1, - 'currentGroup' => $group['id'], - ]; - } else { - - foreach ($clients as $client) { - $phone = ClientsPhone::where('client_guid', '=', $client['user_code'])->first(); - $out[] = array('id' => $client['id'], 'name' => $client['name'], 'phone' => $phone['phone']); - } - return [ - 'status' => 'success', - 'clients' => $out, - 'total' => $total, - 'size' => $countPerPage, - 'pages' => ceil($total / $countPerPage), - 'currentGroup' => $group['id'], - ]; - } - } -} \ No newline at end of file diff --git a/commands/Bot.php b/commands/GETBot.php similarity index 95% rename from commands/Bot.php rename to commands/GETBot.php index 3cc7e79..d4b90a6 100644 --- a/commands/Bot.php +++ b/commands/GETBot.php @@ -10,7 +10,7 @@ use App\Component\Models\Tasks; use App\Console\Commands\HRCCommand; use App\Console\Commands\HRCCommandInterface; -class Bot extends HRCCommand implements HRCCommandInterface +class GETBot extends HRCCommand implements HRCCommandInterface { protected $signature = 'getbot'; diff --git a/commands/ClientFile.php b/commands/GETClientFile.php similarity index 97% rename from commands/ClientFile.php rename to commands/GETClientFile.php index c74eb20..19ff6b4 100644 --- a/commands/ClientFile.php +++ b/commands/GETClientFile.php @@ -7,7 +7,7 @@ use App\Component\Models\Terminal; use App\Console\Commands\HRCCommand; use App\Console\Commands\HRCCommandInterface; -class ClientFile extends HRCCommand implements HRCCommandInterface { +class GETClientFile extends HRCCommand implements HRCCommandInterface { protected $signature = 'getclientfile'; public function command($input, $output = null) { diff --git a/commands/GETClientInfo.php b/commands/GETClientInfo.php new file mode 100644 index 0000000..468fe27 --- /dev/null +++ b/commands/GETClientInfo.php @@ -0,0 +1,58 @@ +first(); + $client_guid = $client['user_code']; + $phone = Client::getPhone($client_guid); + $address = Client::getAddress($client_guid); + $email = Client::getEmail($client_guid); + $presale = ClientsPresale::getPresale($client_guid); + $bonus = ClientsBonus::getBonus($client_guid); + $orders_count_exchange = ExchangeOrders::where('client_code', $client_guid)->where('is_returned', 0)->where('is_deleted', 0)->count(); + $orders_count_current = ShiftOnlineOrders::where('client_code', $client_guid)->where('is_returned', 0)->where('is_deleted', 0)->count(); + $orders_sum_exchange = ExchangeOrders::where('client_code', $client_guid)->where('is_returned', 0)->where('is_deleted', 0)->sum('full_sum'); + $orders_sum_current = ShiftOnlineOrders::where('client_code', $client_guid)->where('is_returned', 0)->where('is_deleted', 0)->sum('full_sum'); + $orders_count = $orders_count_exchange + $orders_count_current; + $orders_sum = $orders_sum_exchange + $orders_sum_current; + $result = array( + 'id' => $client['id'], + 'name' => $client['name'], + 'info' => array( + 'phone' => $phone, + 'email' => $email, + 'address' => $address, + 'order_count' => $orders_count, + 'order_sum' => $orders_sum, + 'presale' => $presale, + 'bonus' => intval($bonus), + ) + ); + return [ + 'status' => 'success', + 'client' => $result, + ]; + } else { + return [ + 'status' => 'error', + 'more' => 'Проверьте введенные данные', + ]; + } + + } +} \ No newline at end of file diff --git a/commands/GETClientLog.php b/commands/GETClientLog.php new file mode 100644 index 0000000..c9981c2 --- /dev/null +++ b/commands/GETClientLog.php @@ -0,0 +1,51 @@ +first(); + $client_guid = $client['user_code']; + $logs = ClientsActions::where('user_id', $client_guid)->orderByDesc('created')->get(); + $info = []; + foreach ($logs as $log) { + $info[] = array( + 'action' => $log['action'], + 'value' => round($log['action_value'], 2), + 'who' => Staff::getName($log['who']), + 'time' => $log['created'], + 'type' => $log['action_type'] + ); + } + $result = array( + 'id' => $client['id'], + 'name' => $client['name'], + 'info' => $info + ); + return [ + 'status' => 'success', + 'client' => $result, + ]; + } else { + return [ + 'status' => 'error', + 'more' => 'Проверьте введенные данные', + ]; + } + + } +} \ No newline at end of file diff --git a/commands/GETClientOrderInfo.php b/commands/GETClientOrderInfo.php new file mode 100644 index 0000000..8f9f97a --- /dev/null +++ b/commands/GETClientOrderInfo.php @@ -0,0 +1,34 @@ +first(); + if ($shift['opened'] > $opened) { + $order = ExchangeOrders::where('opened', $opened)->where('closed', $closed)->where('code', $order_id)->first(); + $shift_id = $order['shift_id']; + $info = ExchangeOrders::getInfo($order_id, $shift_id); + } else { + $info = ShiftOnlineOrders::getInfo($order_id); + } + + return [ + 'status' => 'success', + 'info' => $info[0], + ]; + } +} \ No newline at end of file diff --git a/commands/GETClientOrders.php b/commands/GETClientOrders.php new file mode 100644 index 0000000..ad57d3d --- /dev/null +++ b/commands/GETClientOrders.php @@ -0,0 +1,54 @@ +first(); + $client_guid = $client['user_code']; + $exchange_orders = ExchangeOrders::where('client_code', $client_guid)->where('is_returned', 0)->where('is_deleted', 0)->orderByDesc('closed')->get(); + $online_orders = ShiftOnlineOrders::where('client_code', $client_guid)->where('is_returned', 0)->where('is_deleted', 0)->orderByDesc('closed')->get(); + $orders = []; + foreach ($online_orders as $online_order) { + $orders[] = array( + 'id' => $online_order['code'], + 'opened' => $online_order['opened'], + 'closed' => $online_order['closed'], + 'sum' => $online_order['order_sum'], + 'discount' => $online_order['sale_sum'], + 'shift_id' => 0 + ); + } + foreach ($exchange_orders as $exchange_order) { + $orders[] = array( + 'id' => $exchange_order['code'], + 'opened' => $exchange_order['opened'], + 'closed' => $exchange_order['closed'], + 'sum' => $exchange_order['order_sum'], + 'discount' => $exchange_order['sale_sum'], + 'shift_id' => $exchange_order['shift_id'] + ); + } + return [ + 'status' => 'success', + 'orders' => $orders, + ]; + } else { + return [ + 'status' => 'error', + 'more' => 'Проверьте введенные данные', + ]; + } + } +} \ No newline at end of file diff --git a/commands/GETClients.php b/commands/GETClients.php new file mode 100644 index 0000000..42d9c84 --- /dev/null +++ b/commands/GETClients.php @@ -0,0 +1,166 @@ +timezone('Europe/Minsk'); + $phones = ClientsPhone::where('updated_at', '>=', $last_update)->get(); + $addresses = ClientsAddress::where('updated_at', '>=', $last_update)->get(); + $barcodes = ClientsBarcode::where('updated_at', '>=', $last_update)->get(); + $emails = ClientsEmail::where('updated_at', '>=', $last_update)->get(); + $presales = ClientsPresale::where('updated_at', '>=', $last_update)->get(); + $bonuses = ClientsBonus::where('updated_at', '>=', $last_update)->get(); + $clients = Client::where('updated_at', '>=', $last_update)->get(); + $info = []; + foreach ($phones as $phone) { + $info[] = $phone['client_guid']; + } + foreach ($addresses as $address) { + $info[] = $address['client_guid']; + } + foreach ($barcodes as $barcode) { + $info[] = $barcode['client_guid']; + } + foreach ($emails as $email) { + $info[] = $email['client_guid']; + } + foreach ($presales as $presale) { + $info[] = $presale['client_guid']; + } + foreach ($bonuses as $bonus) { + $info[] = $bonus['client_guid']; + } + foreach ($clients as $client) { + $info[] = $client['user_code']; + } + $guides = array_values(array_unique($info)); + $email = $phone = $client = []; + foreach ($guides as $guid) { + $email_address = Client::getEmail($guid); + $phone_number = Client::getPhone($guid); + $client_info = Client::where('user_code', $guid)->first(); + $email[] = array( + 'email' => $email_address + ); + $phone[] = array( + 'phone' => $phone_number + ); + $badge[] = array( + 'name' => 'Test', + 'code' => 1 + ); + $bonus_dishes[] = array( + 'code' => '' + ); + if (ClientsBonus::getBonus($guid) > 0) { + $bonus_info[] = array( + 'amount' => ClientsBonus::getBonus($guid), + 'dishes' => $bonus_dishes + ); + } else { + $bonus_info[] = array( + 'amount' => ClientsBonus::getBonus($guid) + ); + } + + $group_info = ClientsGroup::where('code', $client_info['group_id'])->first(); + $client[] = array( + 'id' => $client_info['id'], + 'name' => $client_info['name'], + 'guid' => $guid, + 'presale' => ClientsPresale::getPresale($guid), + 'bonuses' => $bonus_info, + 'barcode' => Client::getBarcode($guid), + 'group_id' => $client_info['group_id'], + 'emails' => $email, + 'phones' => $phone, + 'badges' => $badge + ); + $groups[] = $group_info['code']; + $email = $phone = $badge = $bonus_dishes = $bonus_info = []; + } + $groups_guides = array_values(array_unique($groups)); + foreach ($groups_guides as $group) { + $group_info = ClientsGroup::where('code', $group)->first(); + $groups_info[] = array( + 'id' => $group_info['id'], + 'name' => $group_info['name'], + 'guid' => $group_info['code'], + ); + } + + return [ + 'status' => 'success', + 'clients' => $client, + 'groups' => $groups_info, + ]; + } + if (ClientsGroup::where('code', '0')->count() == 0) { + $group = new ClientsGroup([ + 'code' => '0', + 'name' => 'Без группы', + ]); + $group->save(); + } + $countPerPage = 25; + $offset = ($input['page'] - 1) * $countPerPage; + if ($input['group_id'] == 0) { + $group = ClientsGroup::where('code', '=', $input['group_id'])->first(); + } else { + $group = ClientsGroup::where('id', '=', $input['group_id'])->first(); + } + $clients = Client::where('group_id', '=', $group['code'])->skip($offset)->take($countPerPage)->get(); + $total = Client::where('group_id', '=', $group['code'])->count(); + if ($total == NULL) { + return [ + 'status' => 'success', + 'clients' => array(), + 'total' => 0, + 'size' => $countPerPage, + 'pages' => 1, + 'currentGroup' => $group['id'], + ]; + } else { + + foreach ($clients as $client) { + $phone = Client::getPhone($client['user_code']); + $email = Client::getEmail($client['user_code']); + $address = Client::getAddress($client['user_code']); + $out[] = array( + 'id' => $client['id'], + 'name' => $client['name'], + 'phone' => $phone, + 'email' => $email, + 'address' => $address, + ); + } + return [ + 'status' => 'success', + 'clients' => $out, + 'total' => $total, + 'size' => $countPerPage, + 'pages' => ceil($total / $countPerPage), + 'currentGroup' => $group['id'], + ]; + } + } +} \ No newline at end of file diff --git a/commands/GETDiscountItems.php b/commands/GETDiscountItems.php index 77a158d..26397ac 100644 --- a/commands/GETDiscountItems.php +++ b/commands/GETDiscountItems.php @@ -25,11 +25,8 @@ class GETDiscountItems extends HRCCommand implements HRCCommandInterface { } else { $discount = 0; } - $dish = Dishes::where('code', $item['dish_code'])->where('is_history', 0)->first(); - if (!isset($dish)) { - $dish = Dishes::where('legacy_code', $item['dish_code'])->where('is_history', 0)->first(); - } - $items[] = array('name' => $dish['name'], 'discount' => round($discount, 0), 'count' => $item['count'], 'sale_price' => $salePrice, 'sum' => round($realPrice, 2)); + $dish = Dishes::getName($item['menu_code']); + $items[] = array('name' => $dish, 'discount' => round($discount, 0), 'count' => $item['count'], 'sale_price' => $salePrice, 'sum' => round($realPrice, 2)); } return [ diff --git a/commands/Equipment.php b/commands/GETEquipment.php similarity index 93% rename from commands/Equipment.php rename to commands/GETEquipment.php index fc67277..78d312e 100644 --- a/commands/Equipment.php +++ b/commands/GETEquipment.php @@ -8,7 +8,7 @@ use App\Component\Models\Terminal; use App\Console\Commands\HRCCommand; use App\Console\Commands\HRCCommandInterface; -class Equipment extends HRCCommand implements HRCCommandInterface { +class GETEquipment extends HRCCommand implements HRCCommandInterface { protected $signature = 'getequipment'; public function command($input, $output = null) { diff --git a/commands/HelloWorld.php b/commands/GETHelloWorld.php similarity index 81% rename from commands/HelloWorld.php rename to commands/GETHelloWorld.php index 4ab7d74..25838e5 100644 --- a/commands/HelloWorld.php +++ b/commands/GETHelloWorld.php @@ -6,7 +6,7 @@ use App\Component\Models\User; use App\Console\Commands\HRCCommand; use App\Console\Commands\HRCCommandInterface; -class HelloWorld extends HRCCommand implements HRCCommandInterface { +class GETHelloWorld extends HRCCommand implements HRCCommandInterface { protected $signature = 'gethello'; public function command($input, $output = null) { diff --git a/commands/Import.php b/commands/GETImport.php similarity index 97% rename from commands/Import.php rename to commands/GETImport.php index 5593ee9..af98963 100644 --- a/commands/Import.php +++ b/commands/GETImport.php @@ -6,7 +6,7 @@ use App\Component\Models\Terminal; use App\Console\Commands\HRCCommand; use App\Console\Commands\HRCCommandInterface; -class Import extends HRCCommand implements HRCCommandInterface { +class GETImport extends HRCCommand implements HRCCommandInterface { protected $signature = 'getimport'; public function command($input, $output = null) { diff --git a/commands/GETOnlineStaff.php b/commands/GETOnlineStaff.php index a5f03d5..a5dbe8f 100644 --- a/commands/GETOnlineStaff.php +++ b/commands/GETOnlineStaff.php @@ -9,93 +9,92 @@ use App\Component\Models\Staff; use App\Console\Commands\HRCCommand; use App\Console\Commands\HRCCommandInterface; -class GETOnlineStaff extends HRCCommand implements HRCCommandInterface { - protected $signature = 'getonlinestaff'; +class GETOnlineStaff extends HRCCommand implements HRCCommandInterface +{ + protected $signature = 'getonlinestaff'; - public function command($input, $output = null) { - function staffName($data) { - $staff_name = Staff::where('code', $data)->where('is_history', 0)->first(); - if ($staff_name) { - $staff_name = $staff_name['name']; - } else { - $staff_name = Staff::where('code', $data)->where('is_history', 1)->first(); - if ($staff_name) { - $staff_name = $staff_name['name']; - } else { - $staff_name = 'Связанный персонал не найден'; - } - } - return $staff_name; - } - if ($input['method'] == 'dashboard') { - $staff_data = []; - $staffs = ShiftOnlineOrders::select('who_open') - ->where('is_deleted', 0) - ->where('is_returned', 0) - ->where('order_sum', '>', 0) - ->groupBy('who_open') - ->get(); - foreach ($staffs as $key => $staff) { - $count = ShiftOnlineOrders::where('who_open', $staff['who_open']) - ->where('is_deleted', 0) - ->where('is_returned', 0) - ->where('order_sum', '>', 0) - ->count(); - $name = staffName($staff['who_open']); - $code = $staff['who_open']; - $sum = ShiftOnlineOrders::where('who_open', $staff['who_open']) - ->where('is_deleted', 0) - ->where('is_returned', 0) - ->where('order_sum', '>', 0) - ->sum('order_sum'); - $staff_data[] = array('name' => $name, 'code' => $code + 0, 'orders_count' => $count + 0, 'orders_sum' => $sum + 0); - } + public function command($input, $output = null) + { + if ($input['method'] == 'dashboard') { + $staff_data = []; + $staffs = ShiftOnlineOrders::select('who_open') + ->where('is_deleted', 0) + ->where('is_returned', 0) + ->where('order_sum', '>', 0) + ->groupBy('who_open') + ->get(); + foreach ($staffs as $staff) { + $count = ShiftOnlineOrders::where('who_open', $staff['who_open']) + ->where('is_deleted', 0) + ->where('is_returned', 0) + ->where('order_sum', '>', 0) + ->count(); + $name = Staff::getName($staff['who_open']); + $code = $staff['who_open']; + $sum = ShiftOnlineOrders::where('who_open', $staff['who_open']) + ->where('is_deleted', 0) + ->where('is_returned', 0) + ->where('order_sum', '>', 0) + ->sum('order_sum'); + $staff_data[] = array( + 'name' => $name, + 'code' => $code + 0, + 'orders_count' => $count + 0, + 'orders_sum' => $sum + 0 + ); + } - return [ - 'status' => 'success', - 'staff' => $staff_data, - ]; - } - if ($input['method'] == 'items') { - if (isset($input['order'])) { - $orderId = $input['order'] + 0; - $items = []; - $order = ShiftOnlineOrders::where('code', $orderId)->first(); - $who_open = staffName($order['who_open']); - if ($order['who_close'] == 0) { - $who_close = '-'; - } else { - $who_close = staffName($order['who_close']); - } + return [ + 'status' => 'success', + 'staff' => $staff_data, + ]; + } + if ($input['method'] == 'items') { + if (isset($input['order'])) { + $orderId = $input['order'] + 0; + $items = []; + $order = ShiftOnlineOrders::where('code', $orderId)->first(); + $who_open = Staff::getName($order['who_open']); + if ($order['who_close'] == 0) { + $who_close = '-'; + } else { + $who_close = Staff::getName($order['who_close']); + } - $onlineItems = ShiftOnlineItems::where('order_code', $order['code'])->where('modificator_code', 0)->get(); - foreach ($onlineItems as $key => $item) { - $realPrice = $item['real_price'] * $item['count'] * $item['cof']; - $salePrice = $item['sale_price'] * $item['count']; - if ($realPrice > 0) { - $discount = $salePrice / $realPrice; - $discount = (1 - $discount) * 100; - } else { - $discount = 0; - } - $dish = Dishes::where('code', $item['dish_code'])->where('is_history', 0)->first(); - $items[] = array('name' => $dish['name'], 'discount' => round($discount, 0), 'count' => $item['count'], 'sale_price' => $salePrice, 'sum' => round($realPrice, 2)); - } - } else { - return [ - 'status' => 'success', - 'message' => 'Проверьте введенные данные', - ]; - } - return [ - 'status' => 'success', - 'who_open' => $who_open, - 'who_close' => $who_close, - 'title' => 'Подробнее о заказе №' . $order['code'], - 'total' => $order['order_sum'], - 'items' => $items, - ]; - } + $onlineItems = ShiftOnlineItems::where('order_code', $order['code'])->where('modificator_code', 0)->get(); + foreach ($onlineItems as $item) { + $realPrice = $item['real_price'] * $item['count'] * $item['cof']; + $salePrice = $item['sale_price'] * $item['count']; + if ($realPrice > 0) { + $discount = $salePrice / $realPrice; + $discount = (1 - $discount) * 100; + } else { + $discount = 0; + } + $dish_name = Dishes::getName($item['menu_code']); + $items[] = array( + 'name' => $dish_name, + 'discount' => round($discount, 0), + 'count' => $item['count'], + 'sale_price' => $salePrice, + 'sum' => round($realPrice, 2) + ); + } + } else { + return [ + 'status' => 'success', + 'message' => 'Проверьте введенные данные', + ]; + } + return [ + 'status' => 'success', + 'who_open' => $who_open, + 'who_close' => $who_close, + 'title' => 'Подробнее о заказе №' . $order['code'], + 'total' => $order['order_sum'], + 'items' => $items, + ]; + } - } + } } \ No newline at end of file diff --git a/commands/GETOrder.php b/commands/GETOrder.php index fa7490d..847e95f 100644 --- a/commands/GETOrder.php +++ b/commands/GETOrder.php @@ -6,6 +6,7 @@ use App\Component\Models\Client; use App\Component\Models\ClientsAddress; use App\Component\Models\ClientsPhone; use App\Component\Models\Dishes; +use App\Component\Models\Modifier; use App\Component\Models\OrderItems; use App\Component\Models\Orders; use App\Console\Commands\HRCCommand; diff --git a/commands/OutOrders.php b/commands/GETOutOrders.php similarity index 98% rename from commands/OutOrders.php rename to commands/GETOutOrders.php index 1936f5f..dd1cdb3 100644 --- a/commands/OutOrders.php +++ b/commands/GETOutOrders.php @@ -8,7 +8,7 @@ use App\Component\Models\Report; use App\Console\Commands\HRCCommand; use App\Console\Commands\HRCCommandInterface; -class OutOrders extends HRCCommand implements HRCCommandInterface { +class GETOutOrders extends HRCCommand implements HRCCommandInterface { protected $signature = 'getoutorders'; public function command($input, $output = null) { diff --git a/commands/TopDishes.php b/commands/GETTopDishes.php similarity index 97% rename from commands/TopDishes.php rename to commands/GETTopDishes.php index 345ce24..edf4b7f 100644 --- a/commands/TopDishes.php +++ b/commands/GETTopDishes.php @@ -8,7 +8,7 @@ use App\Component\Models\Terminal; use App\Console\Commands\HRCCommand; use App\Console\Commands\HRCCommandInterface; -class TopDishes extends HRCCommand implements HRCCommandInterface { +class GETTopDishes extends HRCCommand implements HRCCommandInterface { protected $signature = 'gettopdishes'; public function command($input, $output = null) { diff --git a/commands/TopDishesNewYear.php b/commands/GETTopDishesNewYear.php similarity index 98% rename from commands/TopDishesNewYear.php rename to commands/GETTopDishesNewYear.php index bcf9a2a..7d8331a 100644 --- a/commands/TopDishesNewYear.php +++ b/commands/GETTopDishesNewYear.php @@ -9,7 +9,7 @@ use App\Component\Models\Terminal; use App\Console\Commands\HRCCommand; use App\Console\Commands\HRCCommandInterface; -class TopDishesNewYear extends HRCCommand implements HRCCommandInterface { +class GETTopDishesNewYear extends HRCCommand implements HRCCommandInterface { protected $signature = 'gettopdishesnewyear'; public function command($input, $output = null) { diff --git a/commands/POSTBonus.php b/commands/POSTBonus.php new file mode 100644 index 0000000..7b3b102 --- /dev/null +++ b/commands/POSTBonus.php @@ -0,0 +1,34 @@ + 0) { + $message = 'Начислено ' . $bonus_amount . ' бонусов'; + } else { + $message = 'Списано ' . abs($bonus_amount) . ' бонусов'; + } + $bonus_result = ClientsBonus::getBonus($client_guid); + return [ + 'status' => 'success', + 'message' => $message, + 'result' => $bonus_result + ]; + } +} \ No newline at end of file diff --git a/commands/CreateBarcode.php b/commands/POSTCreateBarcode.php similarity index 94% rename from commands/CreateBarcode.php rename to commands/POSTCreateBarcode.php index ed6f023..2188fe6 100644 --- a/commands/CreateBarcode.php +++ b/commands/POSTCreateBarcode.php @@ -8,7 +8,7 @@ use App\Component\Models\ClientsGroup; use App\Console\Commands\HRCCommand; use App\Console\Commands\HRCCommandInterface; -class CreateBarcode extends HRCCommand implements HRCCommandInterface { +class POSTCreateBarcode extends HRCCommand implements HRCCommandInterface { protected $signature = 'postcreatebarcode'; public function command($input, $output = null) { diff --git a/commands/CreateClient.php b/commands/POSTCreateClient.php similarity index 97% rename from commands/CreateClient.php rename to commands/POSTCreateClient.php index 28238fe..f3c3332 100644 --- a/commands/CreateClient.php +++ b/commands/POSTCreateClient.php @@ -11,7 +11,7 @@ use App\Component\Models\ClientsPhone; use App\Console\Commands\HRCCommand; use App\Console\Commands\HRCCommandInterface; -class CreateClient extends HRCCommand implements HRCCommandInterface { +class POSTCreateClient extends HRCCommand implements HRCCommandInterface { protected $signature = 'postcreateclient'; public function command($input, $output = null) { diff --git a/commands/Fiscals.php b/commands/POSTFiscals.php similarity index 88% rename from commands/Fiscals.php rename to commands/POSTFiscals.php index 9ae6f33..03847cc 100644 --- a/commands/Fiscals.php +++ b/commands/POSTFiscals.php @@ -6,7 +6,7 @@ use App\Component\Models\Terminal; use App\Console\Commands\HRCCommand; use App\Console\Commands\HRCCommandInterface; -class Fiscals extends HRCCommand implements HRCCommandInterface { +class POSTFiscals extends HRCCommand implements HRCCommandInterface { protected $signature = 'postfiscals'; public function command($input, $output = null) { diff --git a/commands/POSTPresale.php b/commands/POSTPresale.php new file mode 100644 index 0000000..4ee1c4c --- /dev/null +++ b/commands/POSTPresale.php @@ -0,0 +1,33 @@ + 0) { + $message = 'Внесен аванс на сумму ' . $presale_amount . ' BYN'; + } else { + $message = 'Зачтен аванс на сумму ' . abs($presale_amount) . ' BYN'; + } + $presale_result = ClientsPresale::getPresale($client_guid); + return [ + 'status' => 'success', + 'message' => $message, + 'result' => $presale_result + ]; + } +} \ No newline at end of file diff --git a/commands/Printers.php b/commands/POSTPrinters.php similarity index 98% rename from commands/Printers.php rename to commands/POSTPrinters.php index 90173e0..1371071 100644 --- a/commands/Printers.php +++ b/commands/POSTPrinters.php @@ -9,7 +9,7 @@ use App\Component\Models\Terminal; use App\Console\Commands\HRCCommand; use App\Console\Commands\HRCCommandInterface; -class Printers extends HRCCommand implements HRCCommandInterface { +class POSTPrinters extends HRCCommand implements HRCCommandInterface { protected $signature = 'postprinters'; public function command($input, $output = null) { diff --git a/database/migrations/2022_09_22_140748_update_core_interface.php b/database/migrations/2022_09_22_140748_update_core_interface.php index 0ae9f4a..c17ae88 100644 --- a/database/migrations/2022_09_22_140748_update_core_interface.php +++ b/database/migrations/2022_09_22_140748_update_core_interface.php @@ -47,9 +47,9 @@ class UpdateCoreInterface extends Migration copy($indexUpd . $file, CORE_PATH . '/../../web/app/' . $file); } } - if (file_exists(CORE_PATH . '/../V1/forUpdate/')) { +/* if (file_exists(CORE_PATH . '/../V1/forUpdate/')) { deleteFolder(CORE_PATH . '/../V1/forUpdate/'); - } + }*/ } /** diff --git a/database/migrations/2022_11_29_003015_create_clients_presales_table.php b/database/migrations/2022_11_29_003015_create_clients_presales_table.php new file mode 100644 index 0000000..7a48836 --- /dev/null +++ b/database/migrations/2022_11_29_003015_create_clients_presales_table.php @@ -0,0 +1,32 @@ +id(); + $table->string('client_guid'); + $table->decimal('value', $precision = 16, $scale = 2)->default(0); + $table->timestamps(); + }); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() { + Schema::dropIfExists('clients_presales'); + } +} diff --git a/database/migrations/2022_12_02_233015_create_clients_bonuses_table.php b/database/migrations/2022_12_02_233015_create_clients_bonuses_table.php new file mode 100644 index 0000000..be6b981 --- /dev/null +++ b/database/migrations/2022_12_02_233015_create_clients_bonuses_table.php @@ -0,0 +1,32 @@ +id(); + $table->string('client_guid'); + $table->decimal('value', $precision = 16, $scale = 2)->default(0); + $table->timestamps(); + }); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() { + Schema::dropIfExists('clients_bonuses'); + } +} diff --git a/database/seeders/AddStaffRights.php b/database/seeders/AddStaffRights.php index 64ff500..cdb8aee 100644 --- a/database/seeders/AddStaffRights.php +++ b/database/seeders/AddStaffRights.php @@ -29,5 +29,8 @@ class AddStaffRights extends Seeder if (Right::where('code', 'eorders')->count() == 0) { Right::add('eorders', 'Онлайн заказы'); } + if (Right::where('code', 'loyalty')->count() == 0) { + Right::add('loyalty', 'Loyalty'); + } } } diff --git a/database/seeders/AddUserRights.php b/database/seeders/AddUserRights.php index 7abb312..dbb85ff 100644 --- a/database/seeders/AddUserRights.php +++ b/database/seeders/AddUserRights.php @@ -29,5 +29,8 @@ class AddUserRights extends Seeder if (StaffRights::where('code', 'RIGHT_61')->count() == 0) { StaffRights::add('RIGHT_61', 'Печать копии чека из журнала заказов'); } + if (StaffRights::where('code', 'RIGHT_62')->count() == 0) { + StaffRights::add('RIGHT_62', 'Отправка чека на email'); + } } } diff --git a/models/Client.php b/models/Client.php index 8524e74..dedfa28 100644 --- a/models/Client.php +++ b/models/Client.php @@ -13,4 +13,55 @@ class Client extends Model { public function clientPhone() { return $this->belongsTo('App\Component\Models\ClientsPhone', 'user_code', 'client_guid'); } + + public static function getPhone($guid) { + $phone = ClientsPhone::where('client_guid', $guid)->first(); + if (isset($phone)) { + $phone = $phone['phone']; + } else { + $phone = ''; + } + return $phone; + } + + public static function getEmail($guid) { + $email = ClientsEmail::where('client_guid', $guid)->first(); + if (isset($email)) { + $email = $email['email']; + } else { + $email = ''; + } + return $email; + } + + public static function getAddress($guid) { + $address = ClientsAddress::where('client_guid', $guid)->first(); + if (isset($address)) { + $address = $address['address']; + } else { + $address = ''; + } + return $address; + } + + public static function getBarcode($guid) { + $barcode = ClientsBarcode::where('client_guid', $guid)->first(); + if (isset($barcode)) { + $barcode = $barcode['value']; + } else { + $barcode = ''; + } + return $barcode; + } + + public static function getID($guid) { + $id = Client::where('client_guid', $guid)->first(); + if (isset($id)) { + $id = $id['id']; + } else { + $id = ''; + } + return $id; + } + } \ No newline at end of file diff --git a/models/ClientsActions.php b/models/ClientsActions.php new file mode 100644 index 0000000..694688a --- /dev/null +++ b/models/ClientsActions.php @@ -0,0 +1,11 @@ +first(); + if (isset($bonus)) { + $bonus = $bonus['value']; + } else { + $bonus = 0; + } + return $bonus; + } + + /** + * Save bonus value. + */ + public static function bonusReg($guid, $value) + { + $bonus_value = ClientsBonus::where('client_guid', $guid)->first(); + $bonus = ClientsBonus::updateOrCreate( + ['client_guid' => $guid], + ['value' => $bonus_value['value'] + $value] + ); + + return $bonus['value']; + } + + /** + * Bonus log. + */ + public static function bonusLog($guid, $value, $time, $staff_id) + { + if ($value > 0) { + $action_name = 'Зачиление бонусов'; + } else { + $action_name = 'Списание бонусов'; + } + $action = new ClientsActions(); + $action->action = $action_name; + $action->created = Carbon::createFromTimestampUTC($time)->timezone('Europe/Minsk'); + $action->user_id = $guid; + $action->action_value = abs($value); + $action->action_type = 1; + $action->who = $staff_id; + $action->save(); + } +} \ No newline at end of file diff --git a/models/ClientsPresale.php b/models/ClientsPresale.php new file mode 100644 index 0000000..3be97fe --- /dev/null +++ b/models/ClientsPresale.php @@ -0,0 +1,60 @@ +first(); + if (isset($presale)) { + $presale = $presale['value']; + } else { + $presale = 0; + } + return $presale; + } + + /** + * Save presale value. + */ + public static function presaleReg($guid, $value) + { + $presale_value = ClientsPresale::where('client_guid', $guid)->first(); + $presale = ClientsPresale::updateOrCreate( + ['client_guid' => $guid], + ['value' => $presale_value['value'] + $value] + ); + + return $presale['value']; + } + + /** + * Presale log. + */ + public static function presaleLog($guid, $value, $time, $staff_id) + { + if ($value > 0) { + $action_name = 'Внесение аванса'; + } else { + $action_name = 'Зачет аванса'; + } + $action = new ClientsActions(); + $action->action = $action_name; + $action->created = Carbon::createFromTimestampUTC($time)->timezone('Europe/Minsk'); + $action->user_id = $guid; + $action->action_value = abs($value); + $action->action_type = 2; + $action->who = $staff_id; + $action->save(); + } +} \ No newline at end of file diff --git a/models/ExchangeOrders.php b/models/ExchangeOrders.php index deb5ba3..4ecd58b 100644 --- a/models/ExchangeOrders.php +++ b/models/ExchangeOrders.php @@ -4,6 +4,78 @@ namespace App\Component\Models; use Illuminate\Database\Eloquent\Model; -class ExchangeOrders extends Model { - protected $table = 'exchange_orders'; +class ExchangeOrders extends Model +{ + protected $table = 'exchange_orders'; + + /** + * Get order info + */ + public static function getInfo($order_id, $shift_id) + { + $order = ExchangeOrders::where('code', $order_id)->where('shift_id', $shift_id)->first(); + $open_time = $order['opened']; + $close_time = $order['closed']; + $who_open = Staff::getName($order['who_open']); + $who_close = Staff::getName($order['who_close']); + $items = ExchangeItems::where('order_code', $order_id)->where('shift_id', $shift_id)->get(); + $order_status = ''; + if ($order['is_deleted'] > 0) { + $order_status = 'Удален'; + } elseif ($order['is_returned'] > 0) { + $order_status = 'Возвращен'; + } elseif ($order['is_waited'] > 0 && $order['is_closed'] < 1) { + $order_status = 'В ожидании'; + } else { + $order_status = 'Оплачен'; + } + $order_cash = $order['cash']; + $order_credit = $order['credit']; + $order_clearing = $order['clearing']; + $order_presale = $order['presale']; + $order_self = $order['self']; + $order_info = []; + $amount = $full_price = 0; + foreach ($items as $key => $item) { + $realPrice = $item['real_price'] * $item['count'] * $item['cof']; + $salePrice = $item['sale_price'] * $item['count']; + if ($realPrice > 0) { + $discount = $salePrice / $realPrice; + $discount = (1 - $discount) * 100; + } else { + $discount = 0; + } + $order_info[] = array( + 'id' => $key + 1, + 'name' => Dishes::getName($item['dish_code']), + 'count' => $item['count'], + 'price' => $item['real_price'], + 'sale_price' => $item['sale_price'], + 'cof' => $item['cof'], + 'unit' => Units::getName($item['units_id']), + 'amount' => round($item['sale_price'] * $item['count'], 2), + 'discount' => round($discount, 2) + ); + $amount += round($item['sale_price'] * $item['count'], 2); + $full_price += round($realPrice,2); + } + $order = []; + $order[] = array( + 'order_id' => $order_id, + 'opened' => $open_time, + 'closed' => $close_time, + 'who_open' => $who_open, + 'who_close' => $who_close, + 'order_status' => $order_status, + 'amount' => $amount, + 'full_price' => $full_price, + 'cash' => $order_cash, + 'credit' => $order_credit, + 'clearing' => $order_clearing, + 'self' => $order_self, + 'presale' => $order_presale, + 'items' => $order_info + ); + return $order; + } } \ No newline at end of file diff --git a/models/ShiftOnlineOrders.php b/models/ShiftOnlineOrders.php index 47885fa..88bdef2 100644 --- a/models/ShiftOnlineOrders.php +++ b/models/ShiftOnlineOrders.php @@ -4,6 +4,78 @@ namespace App\Component\Models; use Illuminate\Database\Eloquent\Model; -class ShiftOnlineOrders extends Model { - protected $table = 'shift_online_orders'; +class ShiftOnlineOrders extends Model +{ + protected $table = 'shift_online_orders'; + + /** + * Get order info + */ + public static function getInfo($order_id) + { + $order = ShiftOnlineOrders::where('code', $order_id)->first(); + $open_time = $order['opened']; + $close_time = $order['closed']; + $who_open = Staff::getName($order['who_open']); + $who_close = Staff::getName($order['who_close']); + $items = ShiftOnlineItems::where('order_code', $order_id)->get(); + $order_status = ''; + if ($order['is_deleted'] > 0) { + $order_status = 'Удален'; + } elseif ($order['is_returned'] > 0) { + $order_status = 'Возвращен'; + } elseif ($order['is_waited'] > 0 && $order['is_closed'] < 1) { + $order_status = 'В ожидании'; + } else { + $order_status = 'Оплачен'; + } + $order_cash = $order['cash']; + $order_credit = $order['credit']; + $order_clearing = $order['clearing']; + $order_presale = $order['presale']; + $order_self = $order['self']; + $order_info = []; + $amount = $full_price = 0; + foreach ($items as $key => $item) { + $realPrice = $item['real_price'] * $item['count'] * $item['cof']; + $salePrice = $item['sale_price'] * $item['count']; + if ($realPrice > 0) { + $discount = $salePrice / $realPrice; + $discount = (1 - $discount) * 100; + } else { + $discount = 0; + } + $order_info[] = array( + 'id' => $key + 1, + 'name' => Dishes::getName($item['dish_code']), + 'count' => $item['count'], + 'price' => $item['real_price'], + 'sale_price' => $item['sale_price'], + 'cof' => $item['cof'], + 'unit' => Units::getName($item['units_id']), + 'amount' => round($item['sale_price'] * $item['count'], 2), + 'discount' => round($discount, 2) + ); + $amount += round($item['sale_price'] * $item['count'], 2); + $full_price += round($realPrice,2); + } + $order = []; + $order[] = array( + 'order_id' => $order_id, + 'opened' => $open_time, + 'closed' => $close_time, + 'who_open' => $who_open, + 'who_close' => $who_close, + 'order_status' => $order_status, + 'amount' => $amount, + 'full_price' => $full_price, + 'cash' => $order_cash, + 'credit' => $order_credit, + 'clearing' => $order_clearing, + 'self' => $order_self, + 'presale' => $order_presale, + 'items' => $order_info + ); + return $order; + } } \ No newline at end of file diff --git a/models/Units.php b/models/Units.php index 5b9a606..f180147 100644 --- a/models/Units.php +++ b/models/Units.php @@ -4,12 +4,25 @@ namespace App\Component\Models; use Illuminate\Database\Eloquent\Model; -class Units extends Model { - protected $table = 'units'; - /** - * The attributes that aren't mass assignable. - * - * @var array - */ - protected $guarded = []; +class Units extends Model +{ + protected $table = 'units'; + /** + * The attributes that aren't mass assignable. + * + * @var array + */ + protected $guarded = []; + + public static function getName($data) + { + $unit_in_list = UnitsList::where('id', $data)->first(); + $unit_name = Units::where('id', $unit_in_list['unit_id'])->first(); + if ($unit_name) { + $unit_name = $unit_name['name']; + } else { + $unit_name = 'шт'; + } + return $unit_name; + } } \ No newline at end of file diff --git a/web/controllers/clients.js b/web/controllers/clients.js index d85b90d..2a44c12 100644 --- a/web/controllers/clients.js +++ b/web/controllers/clients.js @@ -1,353 +1,364 @@ -(function() { - 'use strict'; - angular - .module('app') - .controller('ClientsCtrl', ClientsCtrl); +(function () { + 'use strict'; + angular + .module('app') + .controller('ClientsCtrl', ClientsCtrl); - ClientsCtrl.$inject = ['$scope', 'smartRequest', 'Notification', '$rootScope', '$timeout']; - function ClientsCtrl($scope, smartRequest, Notification, $rootScope, $timeout) { - $scope.clients = []; - $scope.groups = []; - $scope.statuses = []; - $scope.filedate = ''; - $scope.currentGroupId = 0; - $scope.currentClientId = 0; + ClientsCtrl.$inject = ['$scope', 'smartRequest', 'Notification', '$rootScope', '$timeout']; - $scope.currentClient = {}; - - $scope.orders = []; - $scope.order = {}; + function ClientsCtrl($scope, smartRequest, Notification, $rootScope, $timeout) { + $scope.clients = []; + $scope.groups = []; + $scope.statuses = []; + $scope.filedate = ''; + $scope.currentGroupId = 0; + $scope.currentClientId = 0; - $scope.isCreateNewGroup = false; - $scope.newGroup = {}; - $scope.newBarcode = {}; + $scope.currentClient = {}; - $scope.isCreateNewClient = false; - $scope.newClient = {}; + $scope.orders = []; + $scope.order = {}; - $scope.search = { - query: '' - }; - - var promise = 0; + $scope.isCreateNewGroup = false; + $scope.newGroup = {}; + $scope.newBarcode = {}; - $scope.clientsSearch = function() { - - } + $scope.isCreateNewClient = false; + $scope.newClient = {}; - $scope.update = function() { - smartRequest.get('client/list?page=' + $scope.currentPage, function(data) { - $scope.clients = data.clients; - $scope.countOfPages = data.pages; - $scope.pages = $scope.makePages(); - }); - }; + $scope.search = { + query: '' + }; - $scope.getGroups = function() { - smartRequest.get('v1/clientgroup', function(data) { - $scope.groups = data.groups; - $scope.filedate = data.filedate; - $scope.openGroup({id: 0}); - }); - }; + var promise = 0; - - $scope.openGroup = function(group) { - if (typeof group === 'object') { - $scope.currentGroup = group.id; - } else { - $scope.currentGroup = group; - } - $scope.currentPage = 1; - smartRequest.get('v1/clients?group_id=' + $scope.currentGroup + '&page=' + $scope.currentPage, function(data) { - $scope.clients = data.clients; - $scope.pages = data.pages; - $scope.currentGroup = data.currentGroup; - $scope.total = data.total; - }); + $scope.clientsSearch = function () { - }; - - $scope.editGroup = function (group) { - $scope.contextElement = group; + } - $('#edit-group').modal('toggle'); - console.log(group); - }; + $scope.update = function () { + smartRequest.get('client/list?page=' + $scope.currentPage, function (data) { + $scope.clients = data.clients; + $scope.countOfPages = data.pages; + $scope.pages = $scope.makePages(); + }); + }; - $scope.updateGroup = function () { - $('#edit-group').modal('toggle'); + $scope.getGroups = function () { + smartRequest.get('v1/clientgroup', function (data) { + $scope.groups = data.groups; + $scope.filedate = data.filedate; + $scope.openGroup({id: 0}); + }); + }; - smartRequest.post('v1/clientgroup', { - id: $scope.contextElement.id, - name: $scope.contextElement.name, - task: 'update' - }, function (data) { - if (data.status == 'success') { - Notification.success(data.message); - } - if (data.error_message) { - Notification.error(data.error_message); - } - }); - }; - $scope.removeGroup = function () { - $('#group-confirm-delete').modal('toggle'); - $('#edit-group').modal('toggle'); + $scope.openGroup = function (group) { + if (typeof group === 'object') { + $scope.currentGroup = group.id; + } else { + $scope.currentGroup = group; + } + $scope.currentPage = 1; + smartRequest.get('v1/clients?group_id=' + $scope.currentGroup + '&page=' + $scope.currentPage, function (data) { + $scope.clients = data.clients; + $scope.pages = data.pages; + $scope.currentGroup = data.currentGroup; + $scope.total = data.total; + $scope.closeCard(); + $scope.orders = []; + $scope.currentClient = []; + $scope.clientLogs = []; + }); - smartRequest.post('v1/clientgroup', { - id: $scope.contextElement.id, - task: 'delete' - }, function (data) { - $scope.getGroups(); - if (data.message) { - Notification.success(data.message); - } - if (data.error_message) { - Notification.error(data.error_message); - } - }); - }; - - $scope.editClient = function (client, group) { - $scope.contextElement = client; - $scope.contextGroup = group; - $('#edit-client').modal('toggle'); - console.log(client); - console.log($scope.contextGroup); - }; + }; - $scope.updateClient = function (group) { - $('#edit-client').modal('toggle'); + $scope.editGroup = function (group) { + $scope.contextElement = group; - smartRequest.post('v1/client', { - id: $scope.contextElement.id, - name: $scope.contextElement.name, - group_id: group, - phone: $scope.contextElement.phone, - address: $scope.contextElement.address, - email: $scope.contextElement.email, - barcode: $scope.contextElement.barcode, - task: 'update' - }, function (data) { - if (data.status == 'success') { - Notification.success(data.message); - $scope.openGroup(group); - } - if (data.error_message) { - Notification.error(data.error_message); - } - }); - }; + $('#edit-group').modal('toggle'); + console.log(group); + }; - $scope.removeClient = function () { - $('#client-confirm-delete').modal('toggle'); - $('#edit-client').modal('toggle'); + $scope.updateGroup = function () { + $('#edit-group').modal('toggle'); - smartRequest.post('v1/client', { - id: $scope.contextElement.id, - task: 'delete' - }, function (data) { - $scope.getGroups(); - $scope.openGroup($scope.currentGroup); - if (data.message) { - Notification.success(data.message); - } - if (data.error_message) { - Notification.error(data.error_message); - } - }); - }; + smartRequest.post('v1/clientgroup', { + id: $scope.contextElement.id, + name: $scope.contextElement.name, + task: 'update' + }, function (data) { + if (data.status == 'success') { + Notification.success(data.message); + } + if (data.error_message) { + Notification.error(data.error_message); + } + }); + }; - $scope.pager = function(currentPage) { - smartRequest.get('v1/clients?group_id=' + $scope.currentGroup + '&page=' + $scope.currentPage, function(data) { - $scope.clients = data.clients; - $scope.pages = data.pages; - $scope.currentGroup = data.currentGroup; - $scope.total = data.total; - }); - }; + $scope.removeGroup = function () { + $('#group-confirm-delete').modal('toggle'); + $('#edit-group').modal('toggle'); - $scope.getClients = function() { - if ($scope.search.query.length === 0) { - $scope.openGroup({id: $scope.currentGroupId}); - } - else { - smartRequest.post('client/search', { - name: $scope.search.query - }, - function (data) { - $scope.clients = data.clients; - }); - } - }; + smartRequest.post('v1/clientgroup', { + id: $scope.contextElement.id, + task: 'delete' + }, function (data) { + $scope.getGroups(); + if (data.message) { + Notification.success(data.message); + } + if (data.error_message) { + Notification.error(data.error_message); + } + }); + }; - $scope.openFormCreateGroup = function() { - $scope.currentClientId = 0; - $scope.isCreateNewClient = false; - $scope.isCreateNewBarcode = false; - $scope.isCreateNewGroup = !$scope.isCreateNewGroup; - }; + $scope.editClient = function (client, group) { - $scope.openFormCreateClient = function() { - $scope.currentClientId = 0; - $scope.isCreateNewGroup = false; - $scope.isCreateNewBarcode = false; - $scope.isCreateNewClient = !$scope.isCreateNewClient; - }; + $scope.contextElement = client; + $scope.contextGroup = group; + $('#edit-client').modal('toggle'); + console.log(client); + console.log($scope.contextGroup); + }; - $scope.openFormCreateBarcode = function() { - $scope.currentClientId = 0; - $scope.isCreateNewGroup = false; - $scope.isCreateNewClient = false; - $scope.isCreateNewBarcode = !$scope.isCreateNewBarcode; - smartRequest.get('v1/clientgroup', function(data) { - $scope.groups = data.groups; - }); - }; + $scope.updateClient = function (group) { + $('#edit-client').modal('toggle'); - $scope.createGroup = function() { - smartRequest.post('client/group/create', { - name: $scope.newGroup.name - }, function (data) { - $scope.getGroups(); - $scope.closeCard(); - }); - }; + smartRequest.post('v1/client', { + id: $scope.contextElement.id, + name: $scope.contextElement.name, + group_id: group, + phone: $scope.contextElement.phone, + address: $scope.contextElement.address, + email: $scope.contextElement.email, + barcode: $scope.contextElement.barcode, + task: 'update' + }, function (data) { + if (data.status == 'success') { + Notification.success(data.message); + $scope.openGroup(group); + } + if (data.error_message) { + Notification.error(data.error_message); + } + }); + }; - $scope.createClient = function() { - smartRequest.post('v1/createclient/', { - name: $scope.newClient.name, - group_id: $scope.currentGroup, - phone: $scope.newClient.phone, - address: $scope.newClient.address, - email: $scope.newClient.email, - barcode: $scope.newClient.barcode, - is_special_price: $scope.newClient.special_price - }, function(data) { - $scope.pager($scope.currentGroup); - $scope.closeCard(); - }); - }; + $scope.removeClient = function () { + $('#client-confirm-delete').modal('toggle'); + $('#edit-client').modal('toggle'); - $scope.createBarcode = function() { - console.log($scope.newBarcode.group_id); - smartRequest.post('v1/createbarcode/', { - group_id: $scope.newBarcode.group_id, - start: $scope.newBarcode.start, - end: $scope.newBarcode.end, - }, function(data) { - $scope.getGroups(); - $scope.closeCard(); - }); - }; + smartRequest.post('v1/client', { + id: $scope.contextElement.id, + task: 'delete' + }, function (data) { + $scope.getGroups(); + $scope.openGroup($scope.currentGroup); + if (data.message) { + Notification.success(data.message); + } + if (data.error_message) { + Notification.error(data.error_message); + } + }); + }; - $scope.closeCard = function() { - $scope.isCreateNewGroup = false; - $scope.isCreateNewClient = false; - $scope.isCreateNewBarcode = false; - $scope.currentClientId = 0; - }; + $scope.pager = function (currentPage) { + smartRequest.get('v1/clients?group_id=' + $scope.currentGroup + '&page=' + $scope.currentPage, function (data) { + $scope.clients = data.clients; + $scope.pages = data.pages; + $scope.currentGroup = data.currentGroup; + $scope.total = data.total; + }); + }; - $scope.openClientInfo = function(client) { - $scope.currentClientId = client.id; - $scope.isCreateNewGroup = false; - $scope.isCreateNewClient = false; - $scope.isCreateNewBarcode = false; + $scope.getClients = function () { + if ($scope.search.query.length === 0) { + $scope.openGroup({id: $scope.currentGroupId}); + } else { + smartRequest.post('client/search', { + name: $scope.search.query + }, + function (data) { + $scope.clients = data.clients; + }); + } + }; - smartRequest.get('client/client/info?id=' + $scope.currentClientId, function(data) { - $scope.currentClient = data.client; + $scope.openFormCreateGroup = function () { + $scope.currentClientId = 0; + $scope.isCreateNewClient = false; + $scope.isCreateNewBarcode = false; + $scope.isCreateNewGroup = !$scope.isCreateNewGroup; + }; - smartRequest.get('client/orders?client_id=' + $scope.currentClient.id, function(data) { - $scope.orders = data.orders; - }); - }); - }; + $scope.openFormCreateClient = function () { + $scope.currentClientId = 0; + $scope.isCreateNewGroup = false; + $scope.isCreateNewBarcode = false; + $scope.isCreateNewClient = !$scope.isCreateNewClient; + }; - $scope.getItems = function(order) { - smartRequest.get('client/order?order_id=' + order.id, function(data) { - $scope.order = data; - $('#order').modal('toggle'); - }); - }; - - var mergeFiles = function (statuses) { - if (statuses == 4) { - smartRequest.get('v1/clientfile?complete=1', function(data) { - $scope.filedate = data.filedate; - $scope.filename = data.filename; - $scope.terminalkey = data.terminalKey; - $scope.downloadClientFile(); - $scope.statuses = []; - }); - } - }; - - $scope.createClientFile = function(count) { - smartRequest.get('v1/clientfile?th=1', function(data) { - if(data.status == 'success') { - $scope.statuses.push(data.status); - console.log($scope.statuses); - $scope.statusCount = $scope.statuses.length; - mergeFiles($scope.statusCount); - } - }); - smartRequest.get('v1/clientfile?th=2', function(data) { - if(data.status == 'success') { - $scope.statuses.push(data.status); - console.log($scope.statuses); - $scope.statusCount = $scope.statuses.length; - mergeFiles($scope.statusCount); - } - }); - smartRequest.get('v1/clientfile?th=3', function(data) { - if(data.status == 'success') { - $scope.statuses.push(data.status); - console.log($scope.statuses); - $scope.statusCount = $scope.statuses.length; - mergeFiles($scope.statusCount); - } - }); - smartRequest.get('v1/clientfile?th=4', function(data) { - if(data.status == 'success') { - $scope.statuses.push(data.status); - console.log($scope.statuses); - $scope.statusCount = $scope.statuses.length; - mergeFiles($scope.statusCount); - } - }); - }; - - - $scope.downloadClientFile = function() { - smartRequest.get('v1/clientgroup', function(data) { - window.open(window.location.protocol + '//' + window.location.hostname + '/Exchange/' + $scope.terminalkey +'/'+ $scope.filename); - }); - }; - - $scope.clientsSearch = function () { - if (promise) { - $timeout.cancel(promise); - } - promise = $timeout(function () { - if ($scope.search.query.length === 0) { - $scope.getGroups(); - } - else { - $scope.groups = []; - } + $scope.openFormCreateBarcode = function () { + $scope.currentClientId = 0; + $scope.isCreateNewGroup = false; + $scope.isCreateNewClient = false; + $scope.isCreateNewBarcode = !$scope.isCreateNewBarcode; + smartRequest.get('v1/clientgroup', function (data) { + $scope.groups = data.groups; + }); + }; - $scope.getClients(); - }, 300); - }; - - $scope.clearSearchInput = function () { - $scope.search.query = ''; - $scope.clientsSearch(); - }; + $scope.createGroup = function () { + smartRequest.post('client/group/create', { + name: $scope.newGroup.name + }, function (data) { + $scope.getGroups(); + $scope.closeCard(); + }); + }; - $scope.getGroups(); - } -} + $scope.createClient = function () { + smartRequest.post('v1/createclient/', { + name: $scope.newClient.name, + group_id: $scope.currentGroup, + phone: $scope.newClient.phone, + address: $scope.newClient.address, + email: $scope.newClient.email, + barcode: $scope.newClient.barcode, + is_special_price: $scope.newClient.special_price + }, function (data) { + $scope.pager($scope.currentGroup); + $scope.closeCard(); + }); + }; + + $scope.createBarcode = function () { + console.log($scope.newBarcode.group_id); + smartRequest.post('v1/createbarcode/', { + group_id: $scope.newBarcode.group_id, + start: $scope.newBarcode.start, + end: $scope.newBarcode.end, + }, function (data) { + $scope.getGroups(); + $scope.closeCard(); + }); + }; + + $scope.closeCard = function () { + $scope.isCreateNewGroup = false; + $scope.isCreateNewClient = false; + $scope.isCreateNewBarcode = false; + $scope.currentClientId = 0; + }; + + $scope.openClientInfo = function (client) { + $scope.currentClientId = client.id; + $scope.isCreateNewGroup = false; + $scope.isCreateNewClient = false; + $scope.isCreateNewBarcode = false; + $scope.orders = []; + $scope.currentClient = []; + $scope.clientLogs = []; + smartRequest.get('v1/clientinfo?id=' + $scope.currentClientId, function (data) { + $scope.currentClient = data.client; + smartRequest.get('v1/clientlog?id=' + $scope.currentClient.id, function (data) { + $scope.clientLogs = data.client.info; + }); + }); + }; + + $scope.getOrders = function (client_id) { + smartRequest.get('v1/clientorders?id=' + client_id, function (data) { + $scope.orders = data.orders; + }); + }; + + $scope.getItems = function (order_id, opened, closed) { + smartRequest.get('v1/clientorderinfo?order_id=' + order_id + '&opened=' + opened + '&closed=' + closed, function (data) { + $scope.order = data.info; + $('#order').modal('toggle'); + }); + }; + + var mergeFiles = function (statuses) { + if (statuses == 4) { + smartRequest.get('v1/clientfile?complete=1', function (data) { + $scope.filedate = data.filedate; + $scope.filename = data.filename; + $scope.terminalkey = data.terminalKey; + $scope.downloadClientFile(); + $scope.statuses = []; + }); + } + }; + + $scope.createClientFile = function (count) { + smartRequest.get('v1/clientfile?th=1', function (data) { + if (data.status == 'success') { + $scope.statuses.push(data.status); + console.log($scope.statuses); + $scope.statusCount = $scope.statuses.length; + mergeFiles($scope.statusCount); + } + }); + smartRequest.get('v1/clientfile?th=2', function (data) { + if (data.status == 'success') { + $scope.statuses.push(data.status); + console.log($scope.statuses); + $scope.statusCount = $scope.statuses.length; + mergeFiles($scope.statusCount); + } + }); + smartRequest.get('v1/clientfile?th=3', function (data) { + if (data.status == 'success') { + $scope.statuses.push(data.status); + console.log($scope.statuses); + $scope.statusCount = $scope.statuses.length; + mergeFiles($scope.statusCount); + } + }); + smartRequest.get('v1/clientfile?th=4', function (data) { + if (data.status == 'success') { + $scope.statuses.push(data.status); + console.log($scope.statuses); + $scope.statusCount = $scope.statuses.length; + mergeFiles($scope.statusCount); + } + }); + }; + + + $scope.downloadClientFile = function () { + smartRequest.get('v1/clientgroup', function (data) { + window.open(window.location.protocol + '//' + window.location.hostname + '/Exchange/' + $scope.terminalkey + '/' + $scope.filename); + }); + }; + + $scope.clientsSearch = function () { + if (promise) { + $timeout.cancel(promise); + } + promise = $timeout(function () { + if ($scope.search.query.length === 0) { + $scope.getGroups(); + } else { + $scope.groups = []; + } + + $scope.getClients(); + }, 300); + }; + + $scope.clearSearchInput = function () { + $scope.search.query = ''; + $scope.clientsSearch(); + }; + + $scope.getGroups(); + } + } )(); \ No newline at end of file diff --git a/web/controllers/loyalty.js b/web/controllers/loyalty.js new file mode 100644 index 0000000..c5b9b15 --- /dev/null +++ b/web/controllers/loyalty.js @@ -0,0 +1,340 @@ +(function() { + 'use strict'; + angular + .module('app') + .controller('LoyaltyCtrl', LoyaltyCtrl); + + LoyaltyCtrl.$inject = ['$scope', 'smartRequest', 'Notification']; + function LoyaltyCtrl($scope, smartRequest, Notification) { + $scope.discounts = []; + $scope.currentDiscount = {}; + $scope.terms = []; + $scope.defaultTerm = 0; + $scope.currentTerms = []; + + $scope.readonlyMode = false; + + $scope.selectedElement = { + type: '', + value: 0, + currentModal: '', + param: {}, + info: '', + subtype: '' + }; + + $scope.navigationStack = []; + + $scope.update = function() { + smartRequest.get('discount/list', function(data) { + for(var i = 0; i < data.discounts.length; i++) { + if(data.discounts[i].start_date === '0') { + data.discounts[i].start_date = ''; + } + + if(data.discounts[i].end_date === '0') { + data.discounts[i].end_date = ''; + } + + data.discounts[i].is_enable = data.discounts[i].is_enable === '1'; + data.discounts[i].is_check_all = data.discounts[i].is_check_all === '1'; + } + + $scope.discounts = data.discounts; + }); + }; + + $scope.delete = function() { + $('#edit-discount-confirm-delete').modal('toggle'); + $('#edit-discount').modal('toggle'); + + smartRequest.post('discount/delete', { + id: $scope.currentDiscount.id + }, function(data) { + $scope.update(); + }); + }; + + $scope.add = function() { + $scope.currentDiscount = {}; + $scope.currentDiscount.value_type = '0'; + + $('#new-discount').modal(); + }; + + $scope.create = function() { + $('#new-discount').modal('toggle'); + + smartRequest.post('discount/store', { + name: $scope.currentDiscount.name, + value_type: $scope.currentDiscount.value_type, + value: $scope.currentDiscount.value + }, function(data) { + $scope.update(); + }); + }; + + $scope.edit = function(discount) { + $scope.currentDiscount = discount; + $scope.currentDiscount.new_term_type = $scope.defaultTerm; + + $scope.updateTerms(); + + $('#edit-discount').modal(); + }; + + $scope.save = function() { + $('#edit-discount').modal('toggle'); + + smartRequest.post('discount/update', { + id: $scope.currentDiscount.id, + name: $scope.currentDiscount.name, + value_type: $scope.currentDiscount.value_type, + value: $scope.currentDiscount.value, + is_enable: $scope.currentDiscount.is_enable, + start_date: $scope.currentDiscount.start_date, + end_date: $scope.currentDiscount.end_date, + is_check_all: $scope.currentDiscount.is_check_all + }, function(data) { + for(var i = 0; i < $scope.currentTerms.length; i++) { + var params = []; + + for(var j = 0; j < $scope.currentTerms[i].params.length; j++) { + params.push({ + code: $scope.currentTerms[i].params[j].code, + value: $scope.currentTerms[i].params[j].value, + subtype: $scope.currentTerms[i].params[j].subtype + }); + } + + smartRequest.post('discount/term/update', { + id: $scope.currentTerms[i].id, + is_term: $scope.currentTerms[i].is_term === false, + value: JSON.stringify(params) + }); + } + + Notification.success('Скидка сохранена'); + + $scope.update(); + }); + }; + + $scope.updateTerms = function() { + smartRequest.get('discount/term/list?discount_code=' + $scope.currentDiscount.code, function(data) { + for(var i = 0; i < data.discount_terms.length; i++) { + data.discount_terms[i].is_term = data.discount_terms[i].is_term === '0'; + } + + $scope.currentTerms = data.discount_terms; + }); + }; + + $scope.addTerm = function() { + smartRequest.post('discount/term/store', { + discount_code: $scope.currentDiscount.code, + discount_type: $scope.currentDiscount.new_term_type + }, function(data) { + $scope.update(); + $scope.updateTerms(); + }); + }; + + $scope.askDeleteTerm = function(term) { + $scope.currentTerm = term; + + $('#edit-term-confirm-delete').modal(); + }; + + $scope.deleteTerm = function() { + $('#edit-term-confirm-delete').modal('toggle'); + + smartRequest.post('discount/term/delete', { + id: $scope.currentTerm.id + }, function(data) { + $scope.updateTerms(); + }); + }; + + /* MENU BLOCK */ + $scope.selectMenuItemParams = { + currentMenu: 0, + currentFolder: 0, + menus: [], + folders: [], + items: [] + }; + + $scope.selectedMenuElement = {}; + $scope.selectMenuNavigationStack = []; + + $scope.selectMenuItem = function() { + $scope.selectMenuItemParams = { + currentMenu: 0, + currentFolder: 0, + menus: [], + folders: [], + items: [] + }; + + smartRequest.get('menu/list', function (data) { + $scope.selectMenuItemParams.menus = data.menus; + }); + }; + + $scope.openMenuItem = function(menu) { + $scope.selectMenuItemParams.currentMenu = menu.id; + + $scope.selectMenuNavigationStack.push({ + type: 'menu', + value: menu + }); + + smartRequest.get('menu/folder/list?menu_id=' + $scope.selectMenuItemParams.currentMenu + '&parent_id=0', function (data) { + $scope.selectMenuItemParams.folders = data.folders; + }); + + smartRequest.get('menu/dish/list?menu_id=' + $scope.selectMenuItemParams.currentMenu + '&parent_id=0', function (data) { + $scope.selectMenuItemParams.items = data.dishes; + }); + }; + + $scope.openFolderItem = function(folder) { + $scope.selectMenuItemParams.currentFolder = folder.id; + + $scope.selectMenuNavigationStack.push({ + type: 'folder', + value: folder + }); + + smartRequest.get('menu/folder/list?menu_id=' + $scope.selectMenuItemParams.currentMenu + '&parent_id=' + $scope.selectMenuItemParams.currentFolder, function (data) { + $scope.selectMenuItemParams.folders = data.folders; + }); + + smartRequest.get('menu/dish/list?menu_id=' + $scope.selectMenuItemParams.currentMenu + '&parent_id=' + $scope.selectMenuItemParams.currentFolder, function (data) { + $scope.selectMenuItemParams.items = data.dishes; + }); + }; + + $scope.upMenuItem = function() { + if($scope.selectMenuNavigationStack.length > 1) { + $scope.selectMenuNavigationStack.pop(); + var page = $scope.selectMenuNavigationStack.pop(); + + if(page.type === 'menu') { + $scope.openMenuItem(page.value); + } + + if(page.type === 'folder') { + $scope.openFolderItem(page.value); + } + } + else { + $scope.selectMenuItem(); + } + }; + /* END MENU BLOCK */ + + /* CLIENT BLOCK */ + $scope.selectClientItemParams = { + clients: [], + groups: [], + isParent: true + }; + + $scope.selectClientItem = function() { + $scope.selectClientItemParams = { + clients: [], + groups: [], + isParent: true + }; + $scope.currentPage = 1; + $scope.pages = 1; + smartRequest.get('v1/clientgroup', function(data) { + $scope.selectClientItemParams.groups = data.groups; + }); + }; + + $scope.openGroup = function(group) { + $scope.selectClientItemParams.isParent = false; + $scope.currentGroup = group.id; + $scope.currentPage = 1; + $scope.selectClientItemParams.groups = []; + $scope.selectClientItemParams.clients = []; + + smartRequest.get('v1/clients?group_id=' + $scope.currentGroup + '&page=' + $scope.currentPage, function(data) { + $scope.selectClientItemParams.clients = data.clients; + $scope.pages = data.pages; + $scope.currentGroup = data.currentGroup; + }); + }; + + $scope.pager = function(currentPage) { + $scope.selectClientItemParams.isParent = false; + $scope.selectClientItemParams.groups = []; + $scope.selectClientItemParams.clients = []; + smartRequest.get('v1/clients?group_id=' + $scope.currentGroup + '&page=' + $scope.currentPage, function(data) { + $scope.selectClientItemParams.clients = data.clients; + $scope.pages = data.pages; + $scope.currentGroup = data.currentGroup; + }); + }; + + $scope.upGroup = function() { + $scope.selectClientItemParams = { + clients: [], + groups: [], + isParent: true + }; + + smartRequest.get('v1/clientgroup', function(data) { + $scope.selectClientItemParams.groups = data.groups; + }); + }; + /* END CLIENT BLOCK */ + + $scope.selectItem = function(value, type, info) { + $scope.selectedElement.value = value; + $scope.selectedElement.type = type; + $scope.selectedElement.info = info; + }; + + $scope.editTermParam = function(param) { + $scope.$eval(param.type[0].toLowerCase() + param.type.slice(1) + '()'); + + $scope.selectedElement = { + type: param.type, + value: param.value, + currentModal: '#edit-' + param.type.toLowerCase(), + param: param, + info: param.info, + subtype: param.subtype + }; + + $($scope.selectedElement.currentModal).modal(); + }; + + $scope.confirmSelect = function() { + $($scope.selectedElement.currentModal).modal('toggle'); + + $scope.selectedElement.param.value = $scope.selectedElement.value; + $scope.selectedElement.param.info = $scope.selectedElement.info; + $scope.selectedElement.param.subtype = $scope.selectedElement.type; + }; + + $scope.update(); + + smartRequest.get('discount/type/list', function(data) { + $scope.terms = data.discount_types; + $scope.defaultTerm = data.default.code; + }); + + smartRequest.get('menu/readonly', function (data) { + $scope.readonlyMode = data.readonly; + + if (data.readonly) { + Notification.error('Режим просмотра!'); + } + }); + } +})(); \ No newline at end of file diff --git a/web/menu_min.js b/web/menu_min.js index d3dba58..29ed179 100644 --- a/web/menu_min.js +++ b/web/menu_min.js @@ -20,6 +20,13 @@ item: [ icon: 'dashboard', order: 0 }, + { + name: 'Loyalty (dev)', + acl: 'loyalty', + url: 'app.loyalty', + icon: 'dashboard', + order: 0 + }, { name: 'Гости', acl: 'clients', diff --git a/web/routes_min.js b/web/routes_min.js index ba84f8d..7b367d5 100644 --- a/web/routes_min.js +++ b/web/routes_min.js @@ -30,6 +30,14 @@ controller: 'RoommapCtrl', resolve: ['scripts/controllers/roommap.js'] }, +{ + code: 'app.loyalty', + url: '/v1/loyalty', + templateUrl: '../views/loyalty/index.html', + data: { title : 'Loyalty' }, + controller: 'LoyaltyCtrl', + resolve: ['scripts/controllers/loyalty.js'] +}, { code: 'app.clients', url: '/clients', diff --git a/web/views/clients/images/client.png b/web/views/clients/images/client.png new file mode 100644 index 0000000..f876b60 Binary files /dev/null and b/web/views/clients/images/client.png differ diff --git a/web/views/clients/index.html b/web/views/clients/index.html index dcd618d..1b70919 100644 --- a/web/views/clients/index.html +++ b/web/views/clients/index.html @@ -1,8 +1,10 @@