File manager - Edit - /home/u816558632/domains/postills.com/public_html/public/app.zip
Back
PK ���Z�inx % Console/Commands/RecurringExpense.phpnu �[��� <?php namespace App\Console\Commands; use App\Transaction; use App\User; use App\Utils\NotificationUtil; use App\Utils\TransactionUtil; use Illuminate\Console\Command; use Illuminate\Support\Facades\DB; class RecurringExpense extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'pos:generateRecurringExpense'; /** * The console command description. * * @var string */ protected $description = 'Creates recurring expenses if enabled'; /** * Create a new command instance. * * @return void */ public function __construct(TransactionUtil $transactionUtil, NotificationUtil $notificationUtil) { parent::__construct(); $this->transactionUtil = $transactionUtil; $this->notificationUtil = $notificationUtil; } /** * Execute the console command. * * @return mixed */ public function handle() { try { ini_set('max_execution_time', 0); ini_set('memory_limit', '512M'); $transactions = Transaction::where('is_recurring', 1) ->where('type', 'expense') ->whereNull('recur_stopped_on') ->whereNotNull('recur_interval') ->whereNotNull('recur_interval_type') ->with(['recurring_invoices', 'business']) ->get(); foreach ($transactions as $transaction) { date_default_timezone_set($transaction->business->time_zone); //inner try-catch block open try { //Check if no. of generated invoices exceed limit $no_of_recurring_invoice_generated = count($transaction->recurring_invoices); if (! empty($transaction->recur_repetitions) && $no_of_recurring_invoice_generated >= $transaction->recur_repetitions) { continue; } //Check if generate interval is today $last_generated = $no_of_recurring_invoice_generated > 0 ? $transaction->recurring_invoices->max('transaction_date') : $transaction->transaction_date; if (! empty($last_generated)) { $last_generated_string = \Carbon::parse($last_generated)->format('Y-m-d'); $last_generated = \Carbon::parse($last_generated_string); $today = \Carbon::parse(\Carbon::now()->format('Y-m-d')); $diff_from_today = 0; if ($transaction->recur_interval_type == 'days') { $diff_from_today = $last_generated->diffInDays($today); } elseif ($transaction->recur_interval_type == 'months') { //check repeat on date and set last generated date part to reapeat on date if (! empty($transaction->subscription_repeat_on)) { $last_generated_string = $last_generated->format('Y-m'); $last_generated = \Carbon::parse($last_generated_string.'-'.$transaction->subscription_repeat_on); } $diff_from_today = $last_generated->diffInMonths($today); } elseif ($transaction->recur_interval_type == 'years') { $diff_from_today = $last_generated->diffInYears($today); } //if last generated is today or less than today then continue if ($diff_from_today == 0) { continue; } //If difference from today is not multiple of recur_interval then continue if ($diff_from_today % $transaction->recur_interval != 0) { continue; } } DB::beginTransaction(); //Create new recurring expense $recurring_expense = $this->transactionUtil->createRecurringExpense($transaction); //Save database notification $created_by = User::find($transaction->created_by); $this->notificationUtil->recurringExpenseNotification($created_by, $recurring_expense); //if admin is different if ($created_by->id != $transaction->business->owner_id) { $admin = User::find($transaction->business->owner_id); $this->notificationUtil->recurringExpenseNotification($admin, $recurring_expense); } DB::commit(); } catch (\Exception $e) { DB::rollBack(); \Log::emergency('File:'.$e->getFile().'Line:'.$e->getLine().'Message:'.$e->getMessage()); } //inner try-catch block close } } catch (\Exception $e) { \Log::emergency('File:'.$e->getFile().'Line:'.$e->getLine().'Message:'.$e->getMessage()); exit($e->getMessage()); } } } PK ���Z,mxu� � ( Console/Commands/CreateDummyBusiness.phpnu �[��� <?php namespace App\Console\Commands; use App\Utils\ModuleUtil; use DB; use Illuminate\Console\Command; use Illuminate\Support\Facades\Artisan; class CreateDummyBusiness extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'pos:dummyBusiness'; /** * The console command description. * * @var string */ protected $description = 'Creates a dummy business in the application'; /** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); } /** * Execute the console command. * * @return mixed */ public function handle() { ini_set('max_execution_time', 0); ini_set('memory_limit', '512M'); DB::beginTransaction(); DB::statement('SET FOREIGN_KEY_CHECKS = 0'); DB::statement('SET default_storage_engine=INNODB;'); // DB::statement("DROP TABLE IF EXISTS barcodes, brands, business, business_locations, cash_registers, cash_register_transactions, categories, contacts, currencies, expense_categories, group_sub_taxes, invoice_layouts, invoice_schemes, migrations, model_has_permissions, model_has_roles, password_resets, permissions, printers, products, product_variations, purchase_lines, roles, role_has_permissions, sessions, stock_adjustment_lines, tax_rates, transactions, transaction_payments, transaction_sell_lines, units, users, variations, variation_location_details, variation_templates, variation_value_templates, transaction_sell_lines_purchase_lines"); // DB::statement("SET FOREIGN_KEY_CHECKS = 1"); Artisan::call('cache:clear'); Artisan::call('migrate:fresh', ['--force' => true]); Artisan::call('db:seed'); Artisan::call('db:seed', ['--class' => 'DummyBusinessSeeder']); //Run the purchase & mapping command //Artisan::call('pos:mapPurchaseSell'); //Call modules dummy $moduleUtil = new ModuleUtil(); $moduleUtil->getModuleData('dummy_data'); //if (config('app.env') == 'demo') { // system('chmod 777 -R /var/www/pos/storage'); //} // DB::commit(); } } PK ���Z �� % Console/Commands/RecurringInvoice.phpnu �[��� <?php namespace App\Console\Commands; use App\Contact; use App\Transaction; use App\User; use App\Utils\NotificationUtil; use App\Utils\ProductUtil; use App\Utils\TransactionUtil; use Illuminate\Console\Command; use Illuminate\Support\Facades\DB; class RecurringInvoice extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'pos:generateSubscriptionInvoices'; /** * The console command description. * * @var string */ protected $description = 'Creates subscribed invoices if enabled'; /** * Create a new command instance. * * @return void */ public function __construct(TransactionUtil $transactionUtil, ProductUtil $productUtil, NotificationUtil $notificationUtil) { parent::__construct(); $this->transactionUtil = $transactionUtil; $this->productUtil = $productUtil; $this->notificationUtil = $notificationUtil; } /** * Execute the console command. * * @return mixed */ public function handle() { try { ini_set('max_execution_time', 0); ini_set('memory_limit', '512M'); $transactions = Transaction::where('is_recurring', 1) ->where('type', 'sell') ->where('status', 'final') ->whereNull('recur_stopped_on') ->whereNotNull('recur_interval') ->whereNotNull('recur_interval_type') ->with(['recurring_invoices', 'sell_lines', 'business', 'sell_lines.product', ]) ->get(); foreach ($transactions as $transaction) { date_default_timezone_set($transaction->business->time_zone); //inner try-catch block open try { //Check if recurring invoice is enabled if (! empty($transaction->business->enabled_modules) && ! in_array('subscription', $transaction->business->enabled_modules)) { continue; } //Check if no. of generated invoices exceed limit $no_of_recurring_invoice_generated = count($transaction->recurring_invoices); if (! empty($transaction->recur_repetitions) && $no_of_recurring_invoice_generated >= $transaction->recur_repetitions) { continue; } //Check if generate interval is today $last_generated = $no_of_recurring_invoice_generated > 0 ? $transaction->recurring_invoices->max('transaction_date') : $transaction->transaction_date; if (! empty($last_generated)) { $last_generated_string = \Carbon::parse($last_generated)->format('Y-m-d'); $last_generated = \Carbon::parse($last_generated_string); $today = \Carbon::parse(\Carbon::now()->format('Y-m-d')); $diff_from_today = 0; if ($transaction->recur_interval_type == 'days') { $diff_from_today = $last_generated->diffInDays($today); } elseif ($transaction->recur_interval_type == 'months') { //check repeat on date and set last generated date part to reapeat on date if (! empty($transaction->subscription_repeat_on)) { $last_generated_string = $last_generated->format('Y-m'); $last_generated = \Carbon::parse($last_generated_string.'-'.$transaction->subscription_repeat_on); } $diff_from_today = $last_generated->diffInMonths($today); } elseif ($transaction->recur_interval_type == 'years') { $diff_from_today = $last_generated->diffInYears($today); } //if last generated is today or less than today then continue if ($diff_from_today == 0) { continue; } //If difference from today is not multiple of today then continue if ($diff_from_today % $transaction->recur_interval != 0) { continue; } } //Check if sell line quantity available; If not save as draft $save_as_draft = false; $out_of_stock_product = null; foreach ($transaction->sell_lines as $sell_line) { if ($sell_line->product->enable_stock == 1) { $current_stock = $this->productUtil->getCurrentStock($sell_line->variation_id, $transaction->location_id); if ($current_stock < $sell_line->quantity) { $out_of_stock_product = $sell_line->product->name.' ('.$sell_line->product->sku.')'; $save_as_draft = true; break; } } } DB::beginTransaction(); //Create new recurring invoice $recurring_invoice = $this->transactionUtil->createRecurringInvoice($transaction, $save_as_draft); //Update variation location details if status is final if ($recurring_invoice->status == 'final') { foreach ($transaction->sell_lines as $sell_line) { $this->productUtil->decreaseProductQuantity( $sell_line->product_id, $sell_line->variation_id, $transaction->location_id, $sell_line->quantity ); } $business = ['id' => $transaction->business_id, 'accounting_method' => $transaction->business->accounting_method, 'location_id' => $transaction->location_id, ]; $this->transactionUtil->mapPurchaseSell($business, $recurring_invoice->sell_lines, 'purchase'); $contact = Contact::find($recurring_invoice->contact_id); //Auto send notification $this->notificationUtil->autoSendNotification($transaction->business_id, 'new_sale', $recurring_invoice, $contact); } $recurring_invoice->out_of_stock_product = $out_of_stock_product; $recurring_invoice->subscription_no = $transaction->subscription_no; //Save database notification $created_by = User::find($transaction->created_by); $this->notificationUtil->recurringInvoiceNotification($created_by, $recurring_invoice); //if admin is different if ($created_by->id != $transaction->business->owner_id) { $admin = User::find($transaction->business->owner_id); $this->notificationUtil->recurringInvoiceNotification($admin, $recurring_invoice); } DB::commit(); } catch (\Exception $e) { DB::rollBack(); \Log::emergency('File:'.$e->getFile().'Line:'.$e->getLine().'Message:'.$e->getMessage()); } //inner try-catch block close } } catch (\Exception $e) { \Log::emergency('File:'.$e->getFile().'Line:'.$e->getLine().'Message:'.$e->getMessage()); exit($e->getMessage()); } } } PK ���Z�X�'h h $ Console/Commands/MapPurchaseSell.phpnu �[��� <?php namespace App\Console\Commands; use App\Business; use App\PurchaseLine; use App\Transaction; use App\Utils\BusinessUtil; use App\Utils\TransactionUtil; use DB; use Illuminate\Console\Command; class MapPurchaseSell extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'pos:mapPurchaseSell'; /** * The console command description. * * @var string */ protected $description = 'Delete existing mapping and Add mapping for purchase & Sell for all transactions of all businesses.'; protected $transactionUtil; /** * Create a new command instance. * * @return void */ public function __construct(TransactionUtil $transactionUtil, BusinessUtil $businessUtil) { parent::__construct(); $this->transactionUtil = $transactionUtil; $this->businessUtil = $businessUtil; } /** * Execute the console command. * * @return mixed */ public function handle() { try { ini_set('max_execution_time', 0); ini_set('memory_limit', '512M'); DB::beginTransaction(); // Refresh database: // ================== // 1. Set variation_location_details as 0. // 2. set variation_location_details as per purchases. // 3. Reset mapping table. // 4. map the purchase to sales. //STEP1 //DB::statement('Update variation_location_details set qty_available = 0'); //Step 2 // $qty_sums = DB::select('Select SUM(pl.quantity) as qty, pl.product_id, pl.variation_id, transactions.location_id from purchase_lines as pl join transactions on pl.transaction_id = transactions.id group by transactions.location_id, pl.product_id, pl.variation_id'); // foreach ($qty_sums as $key => $value) { // DB::statement('update variation_location_details set qty_available = qty_available + ? where variation_id = ? and product_id = ? and location_id = ?', [$value->qty, $value->variation_id, $value->product_id, $value->location_id]); // } //Step 3: Delete existing mapping and sold quantity. DB::table('transaction_sell_lines_purchase_lines')->delete(); PurchaseLine::whereNotNull('created_at') ->update(['quantity_sold' => 0]); //Get all business $businesses = Business::all(); foreach ($businesses as $business) { //Get all transactions $transactions = Transaction::where('business_id', $business->id) ->with('sell_lines') ->where('type', 'sell') ->where('status', 'final') ->orderBy('created_at', 'asc') ->get(); $pos_settings = empty($business->pos_settings) ? $this->businessUtil->defaultPosSettings() : json_decode($business->pos_settings, true); $pos_settings['allow_overselling'] = 1; //Iterate through all transaction and add mapping. First go throught sell_lines having lot number. foreach ($transactions as $transaction) { $business_formatted = ['id' => $business->id, 'accounting_method' => $business->accounting_method, 'location_id' => $transaction->location_id, 'pos_settings' => $pos_settings, ]; foreach ($transaction->sell_lines as $line) { if (! empty($line->lot_no_line_id)) { $this->transactionUtil->mapPurchaseSell($business_formatted, [$line], 'purchase', false); } } } //Then through sell_lines not having lot number foreach ($transactions as $transaction) { $business_formatted = ['id' => $business->id, 'accounting_method' => $business->accounting_method, 'location_id' => $transaction->location_id, 'pos_settings' => $pos_settings, ]; foreach ($transaction->sell_lines as $line) { if (empty($line->lot_no_line_id)) { $this->transactionUtil->mapPurchaseSell($business_formatted, [$line], 'purchase', false); } } } } DB::commit(); } catch (\Exception $e) { DB::rollBack(); \Log::emergency('File:'.$e->getFile().'Line:'.$e->getLine().'Message:'.$e->getMessage()); exit($e->getMessage()); } } } PK ���ZL��Z� � '