<?php namespace App\Classes; use App\Imali\ImaliAccount; use App\Imali\MerchantAccount; use App\Store; class GenerateImaliAccount { public function GenerateImaliAccountNumberAndMetchant() { $characters = '0123456789'; $year = date('Y'); $min = '0000001'; $max = '9999999'; $year = substr( $year, -2); $charactersLength = strlen($characters); $randomCountNumer = ''; for ($i = 0; $i <9 ; $i++) { $randomCountNumer .= $characters[rand(0, $charactersLength - 1)]; } $imaliAccount = ImaliAccount::all()->count(); $comerciante = MerchantAccount::all()->count(); if ($imaliAccount === 0 && $comerciante === 0) { for ($i = $min; $i<$max; $i++) { $imaliNumber = $year.$i; return $imaliNumber; } } else { $comerciante2 = MerchantAccount::all()->count(); if($comerciante2 === 0) { $mali2 = ImaliAccount::all()->last()->account_number; $yearN = date('Y'); $currentYear = substr($yearN, -2); // $lastYear = substr($mali2, -7); $lastYear = substr($mali2, -9, 2); if ($currentYear > $lastYear) { for ($i = $min; $i<$max; $i++) { $imaliNumber = $year.$i; return $imaliNumber; } } else { return $mali2 + 1; } } else { $mali = ImaliAccount::all()->last()->account_number; $co = MerchantAccount::all()->last()->account_number; if ($mali > $co) { // return $mali + 1; $yearN = date('Y'); $currentYear = substr($yearN, -2); // $lastYear = substr($mali, -7); $lastYear = substr($mali, -9, 2); if ($currentYear > $lastYear) { for ($i = $min; $i<$max; $i++) { $imaliNumber = $year.$i; return $imaliNumber; } }else { return $mali + 1; } } if ($co > $mali) { // return $co + 1; $yearN = date('Y'); $currentYear = substr($yearN, -2); // $lastYear = substr($co, -7); $lastYear = substr($mali, -9, 2); if ($currentYear > $lastYear) { for ($i = $min; $i<$max; $i++) { $imaliNumber = $year.$i; return $imaliNumber; } }else { return $co + 1; } } } } } public function GenerateImaliAccountNumber() { $characters = '0123456789'; $year = date('Y'); $min = '0000001'; $max = '9999999'; $year = substr( $year, -2); $charactersLength = strlen($characters); $randomCountNumer = ''; for ($i = 0; $i <9 ; $i++) { $randomCountNumer .= $characters[rand(0, $charactersLength - 1)]; } $imaliAccount = ImaliAccount::all()->count(); if ($imaliAccount === 0) { for ($i = $min; $i<$max; $i++) { $imaliNumber = $year.$i; return $imaliNumber; } } else { $mali = ImaliAccount::all()->last()->account_number; return $mali + 1; } } public function generateReference() { $year = date('Y'); $min = '0000001'; $max = '9999999'; $year = substr( $year, -2); $imaliAccount = ImaliAccount::all()->count(); // $comerciante = MerchantAccount::all()->count(); $comerciante = Store::all()->count(); if ($imaliAccount === 0 && $comerciante === 0) { for ($i = $min; $i<$max; $i++) { $imaliNumber = $year.$i; // return $imaliNumber; $entidade = 11900; $numero = ($entidade.$imaliNumber) * 100; $d = ($numero/97); $integerPart = (int) $d; $cd = 98 - ($numero - 97*$integerPart); if ($cd<=9){ return $imaliNumber.'0'.$cd; }else{ return $imaliNumber.$cd; } // return $imaliNumber.$cd; } } else { // $mali = ImaliAccount::all()->last()->account_number; // $finalNumber =$mali + 1; // $comerciante2 = MerchantAccount::all()->count(); $comerciante2 = Store::all()->count(); if($comerciante2 === 0) { $mali = ImaliAccount::all()->last()->account_number; // $finalNumber = $mali + 1; // return $mali + 1; $yearN = date('Y'); $currentYear = substr($yearN, -2); // $lastYear = substr($mali, -7); $lastYear = substr($mali, -9, 2); if ($currentYear > $lastYear) { for ($i = $min; $i<$max; $i++) { $imaliNumber = $year.$i; // return $imaliNumber; $entidade = 11900; $numero = ($entidade.$imaliNumber) * 100; $d = ($numero/97); $integerPart = (int) $d; $cd = 98 - ($numero - 97*$integerPart); if ($cd<=9){ return $imaliNumber.'0'.$cd; }else{ return $imaliNumber.$cd; } // return $imaliNumber.$cd; } }else { $finalNumber = $mali + 1; } } else { $mali = ImaliAccount::all()->last()->account_number; // $co = MerchantAccount::all()->last()->account_number; $co = Store::all()->last()->account_number; if ($mali > $co) { // $finalNumber =$mali + 1; // return $mali + 1; $yearN = date('Y'); $currentYear = substr($yearN, -2); // $lastYear = substr($mali, -7); $lastYear = substr($mali, -9, 2); if ($currentYear > $lastYear) { for ($i = $min; $i<$max; $i++) { $imaliNumber = $year.$i; // return $imaliNumber; $entidade = 11900; $numero = ($entidade.$imaliNumber) * 100; $d = ($numero/97); $integerPart = (int) $d; $cd = 98 - ($numero - 97*$integerPart); if ($cd<=9){ return $imaliNumber.'0'.$cd; }else{ return $imaliNumber.$cd; } // return $imaliNumber.$cd; } }else { $finalNumber = $mali + 1; } } if ($co > $mali) { // $finalNumber =$co + 1; // return $co + 1; $yearN = date('Y'); $currentYear = substr($yearN, -2); // $lastYear = substr($co, -7); $lastYear = substr($mali, -9, 2); if ($currentYear > $lastYear) { for ($i = $min; $i<$max; $i++) { $imaliNumber = $year.$i; // return $imaliNumber; $entidade = 11900; $numero = ($entidade.$imaliNumber) * 100; $d = ($numero/97); $integerPart = (int) $d; $cd = 98 - ($numero - 97*$integerPart); if ($cd<=9){ return $imaliNumber.'0'.$cd; }else{ return $imaliNumber.$cd; } // return $imaliNumber.$cd; } }else { $finalNumber =$co + 1; } } } $entidade = 11900; $numero = ($entidade.$finalNumber) * 100; $d = ($numero/97); $integerPart = (int) $d; $cd = 98 - ($numero - 97*$integerPart); if ($cd<=9){ return $finalNumber.'0'.$cd; }else{ return $finalNumber.$cd; } // return $finalNumber.$cd; } } // public function generateReference() { // // $year = date('Y'); // $min = '0000001'; // $max = '9999999'; // $year = substr( $year, -2); // $imaliAccount = ImaliAccount::all()->count(); // $comerciante = MerchantAccount::all()->count(); // // if ($imaliAccount === 0 && $comerciante === 0) { // // for ($i = $min; $i<$max; $i++) { // $imaliNumber = $year.$i; //// return $imaliNumber; // // $entidade = 11900; // $numero = ($entidade.$imaliNumber) * 100; // $d = ($numero/97); // // $integerPart = (int) $d; // // $cd = 98 - ($numero - 97*$integerPart); // // return $imaliNumber.$cd; // } // } else { //// $mali = ImaliAccount::all()->last()->account_number; //// $finalNumber =$mali + 1; // $comerciante2 = MerchantAccount::all()->count(); // // if($comerciante2 === 0) { // $mali = ImaliAccount::all()->last()->account_number; // $finalNumber = $mali + 1; //// return $mali + 1; // } else { // // $mali = ImaliAccount::all()->last()->account_number; // $co = MerchantAccount::all()->last()->account_number; // if ($mali > $co) { // $finalNumber =$mali + 1; //// return $mali + 1; // } // if ($co > $mali) { // $finalNumber =$co + 1; //// return $co + 1; // } // } // // // // $entidade = 11900; // $numero = ($entidade.$finalNumber) * 100; // $d = ($numero/97); // // $integerPart = (int) $d; // // $cd = 98 - ($numero - 97*$integerPart); // // return $finalNumber.$cd; // } // } public function GenerateImaliAccountNumberAndStore() { $characters = '0123456789'; $year = date('Y'); $min = '0000001'; $max = '9999999'; $year = substr( $year, -2); $charactersLength = strlen($characters); $randomCountNumer = ''; for ($i = 0; $i <9 ; $i++) { $randomCountNumer .= $characters[rand(0, $charactersLength - 1)]; } $imaliAccount = ImaliAccount::all()->count(); // $comerciante = MerchantAccount::all()->count(); $comerciante = Store::all()->count(); if ($imaliAccount === 0 && $comerciante === 0) { for ($i = $min; $i<$max; $i++) { $imaliNumber = $year.$i; return $imaliNumber; } } else { // $comerciante2 = MerchantAccount::all()->count(); $comerciante2 = Store::all()->count(); if($comerciante2 === 0) { $mali2 = ImaliAccount::all()->last()->account_number; $yearN = date('Y'); $currentYear = substr($yearN, -2); // $lastYear = substr($mali2, -7); $lastYear = substr($mali2, -9, 2); if ($currentYear > $lastYear) { for ($i = $min; $i<$max; $i++) { $imaliNumber = $year.$i; return $imaliNumber; } } else { return $mali2 + 1; } } else { $mali = ImaliAccount::all()->last()->account_number; // $co = MerchantAccount::all()->last()->account_number; $co = Store::all()->last()->account_number; if ($mali > $co) { // return $mali + 1; $yearN = date('Y'); $currentYear = substr($yearN, -2); // $lastYear = substr($mali, -7); $lastYear = substr($mali, -9, 2); if ($currentYear > $lastYear) { for ($i = $min; $i<$max; $i++) { $imaliNumber = $year.$i; return $imaliNumber; } }else { return $mali + 1; } } if ($co > $mali) { // return $co + 1; $yearN = date('Y'); $currentYear = substr($yearN, -2); // $lastYear = substr($co, -7); $lastYear = substr($mali, -9, 2); if ($currentYear > $lastYear) { for ($i = $min; $i<$max; $i++) { $imaliNumber = $year.$i; return $imaliNumber; } }else { return $co + 1; } } } } } public function GenerateImaliAccountNumberAndStoreAndMerchant() { $characters = '0123456789'; $year = date('Y'); $min = '0000001'; $max = '9999999'; $year = substr( $year, -2); $charactersLength = strlen($characters); $randomCountNumer = ''; for ($i = 0; $i <9 ; $i++) { $randomCountNumer .= $characters[rand(0, $charactersLength - 1)]; } $imaliAccount = ImaliAccount::all()->count(); $comerciante = MerchantAccount::all()->count(); $loja = Store::all()->count(); if ($imaliAccount === 0 && $loja === 0 && $comerciante === 0) { for ($i = $min; $i<$max; $i++) { $imaliNumber = $year.$i; return $imaliNumber; } } else { // $comerciante2 = MerchantAccount::all()->count(); // $loja2 = Store::all()->count(); if($loja === 0) { $mali2 = ImaliAccount::all()->last()->account_number; $yearN = date('Y'); $currentYear = substr($yearN, -2); // $lastYear = substr($mali2, -7); $lastYear = substr($mali2, -9, 2); if ($currentYear > $lastYear) { for ($i = $min; $i<$max; $i++) { $imaliNumber = $year.$i; return $imaliNumber; } } else { return $mali2 + 1; } } else { $mali = ImaliAccount::all()->last()->account_number; $com = MerchantAccount::all()->last()->account_number; $lo = Store::all()->last()->account_number; if ($mali > $lo && $mali > $com) { // return $mali + 1; $yearN = date('Y'); $currentYear = substr($yearN, -2); // $lastYear = substr($mali, -7); $lastYear = substr($mali, -9, 2); if ($currentYear > $lastYear) { for ($i = $min; $i<$max; $i++) { $imaliNumber = $year.$i; return $imaliNumber; } }else { return $mali + 1; } } if ($lo > $mali && $lo > $com) { // return $co + 1; $yearN = date('Y'); $currentYear = substr($yearN, -2); // $lastYear = substr($co, -7); $lastYear = substr($mali, -9, 2); if ($currentYear > $lastYear) { for ($i = $min; $i<$max; $i++) { $imaliNumber = $year.$i; return $imaliNumber; } }else { return $lo + 1; } } if ($com > $mali && $com > $lo) { // return $co + 1; $yearN = date('Y'); $currentYear = substr($yearN, -2); // $lastYear = substr($co, -7); $lastYear = substr($mali, -9, 2); if ($currentYear > $lastYear) { for ($i = $min; $i<$max; $i++) { $imaliNumber = $year.$i; return $imaliNumber; } }else { return $com + 1; } } } } } }