Exemplo n.º 1
0
 /**
  * generate ref number
  * 
  * @param model of transaction
  * @return ref number
  */
 public function generateRefNumber($transaction)
 {
     if (is_null($transaction->id) || $transaction->ref_number == '0000000000') {
         if ($transaction->type == 'sell' && in_array($transaction->status, ['na', 'cart', 'abandoned'])) {
             return '0000000000';
         } else {
             $prefix = $transaction->type[0] . date("ym");
             $latest_transaction = Transaction::select('ref_number')->where('ref_number', 'like', $prefix . '%')->status(['wait', 'payment_process', 'paid', 'packed', 'shipping', 'delivered', 'canceled'])->orderBy('ref_number', 'DESC')->first();
             if (date('Y') == '2015') {
                 if (empty($latest_transaction)) {
                     $number = 47;
                 } else {
                     $number = 1 + (int) substr($latest_transaction['ref_number'], 5);
                 }
             } else {
                 if (empty($latest_transaction)) {
                     $number = 1;
                 } else {
                     $number = 1 + (int) substr($latest_transaction['ref_number'], 5);
                 }
             }
             return $prefix . str_pad($number, 4, "0", STR_PAD_LEFT);
         }
     } else {
         return $transaction->ref_number;
     }
 }
Exemplo n.º 2
0
 public function allTransactions()
 {
     $transactions = Transaction::select(['transactions.*', 'orgs.name as org_name', 'property_name', 'tenant_name', \DB::raw("\n\t\t\t\tif(\n\t\t\t\t\ttransactions.note IS NULL OR transactions.note = '',\n\t\t\t\t\tif(\ttransactions.payer = 'tenant_id',\n\t\t\t\t\t\tconcat('Alquiler ',units.unit_name),\n\t\t\t\t\t\t'--'\n\t\t\t\t\t),\n\t\t\t\t\ttransactions.note\n\t\t\t\t) as detail")])->leftJoin('orgs', 'orgs.id', '=', 'transactions.org_id')->leftJoin('properties', 'properties.id', '=', 'transactions.property_id')->leftJoin('tenants', 'tenants.id', '=', 'transactions.tenant_id')->leftJoin('units', 'units.id', '=', 'tenants.unit_id')->where('transactions.property_id', $this->id)->orderBy('paid_at')->get();
     return $transactions;
 }