diff --git a/app/Export/CSV/BaseExport.php b/app/Export/CSV/BaseExport.php index 7dd4b5a9091e..1c0a0294e42e 100644 --- a/app/Export/CSV/BaseExport.php +++ b/app/Export/CSV/BaseExport.php @@ -110,7 +110,7 @@ class BaseExport } } - protected function buildHeader() :array + public function buildHeader() :array { $header = []; diff --git a/app/Services/Report/ARDetail.php b/app/Services/Report/ARDetailReport.php similarity index 94% rename from app/Services/Report/ARDetail.php rename to app/Services/Report/ARDetailReport.php index d26e3febe67b..b8b4c4031b24 100644 --- a/app/Services/Report/ARDetail.php +++ b/app/Services/Report/ARDetailReport.php @@ -11,7 +11,7 @@ namespace App\Services\Report; -class ARDetail +class ARDetailReport { //Date //Invoice # diff --git a/app/Services/Report/ARSummary.php b/app/Services/Report/ARSummaryReport.php similarity index 94% rename from app/Services/Report/ARSummary.php rename to app/Services/Report/ARSummaryReport.php index 44d6132ccd19..a97456542754 100644 --- a/app/Services/Report/ARSummary.php +++ b/app/Services/Report/ARSummaryReport.php @@ -11,7 +11,7 @@ namespace App\Services\Report; -class ARSummary +class ARSummaryReport { //name //total diff --git a/app/Services/Report/ClientBalanceReport.php b/app/Services/Report/ClientBalanceReport.php new file mode 100644 index 000000000000..62cfd4c1bb43 --- /dev/null +++ b/app/Services/Report/ClientBalanceReport.php @@ -0,0 +1,120 @@ +company->db); + App::forgetInstance('translator'); + App::setLocale($this->company->locale()); + $t = app('translator'); + $t->replace(Ninja::transformTranslations($this->company->settings)); + + $this->csv = Writer::createFromString(); + + $this->csv->insertOne([]); + $this->csv->insertOne([]); + $this->csv->insertOne([]); + $this->csv->insertOne([]); + $this->csv->insertOne([ctrans('texts.customer_balance_report')]); + $this->csv->insertOne([ctrans('texts.created_on'),' ',$this->translateDate(now()->format('Y-m-d'), $this->company->date_format(), $this->company->locale())]); + + $this->csv->insertOne($this->buildHeader()); + + Client::query() + ->where('company_id', $this->company->id) + ->where('is_deleted', 0) + ->orderBy('balance', 'desc') + ->cursor() + ->each(function ($client){ + + $this->csv->insertOne($this->buildRow($client)); + + }); + + return $this->csv->toString(); + + } + + public function buildHeader(): array + { + $headers = []; + + foreach($this->report_keys as $key) + $headers[] = ctrans("texts.{$key}"); + + return $headers; + + } + private function buildRow(Client $client): array + { + $query = Invoice::where('client_id', $client->id) + ->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]); + + $query = $this->addDateRange($query); + + return [ + $client->present()->name(), + $client->number, + $client->id_number, + $query->count(), + $query->sum('amount'), + $query->sum('balance'), + $query->sum('total_taxes'), + ]; + } +} \ No newline at end of file diff --git a/app/Services/Report/ClientSales.php b/app/Services/Report/ClientSalesReport.php similarity index 94% rename from app/Services/Report/ClientSales.php rename to app/Services/Report/ClientSalesReport.php index d1df37f69276..1d32b9d92994 100644 --- a/app/Services/Report/ClientSales.php +++ b/app/Services/Report/ClientSalesReport.php @@ -11,7 +11,7 @@ namespace App\Services\Report; -class ClientSales +class ClientSalesReport { //Name //Invoice count diff --git a/app/Services/Report/CustomerBalance.php b/app/Services/Report/CustomerBalance.php deleted file mode 100644 index a45255d2f6a0..000000000000 --- a/app/Services/Report/CustomerBalance.php +++ /dev/null @@ -1,20 +0,0 @@ -scheduler->parameters['entity']); - $class::find($this->decodePrimaryKey($this->scheduler->parameters['entity_id']))->service()->sendEmail(); + $entity = $class::find($this->decodePrimaryKey($this->scheduler->parameters['entity_id'])); + + if($entity) + $entity->service()->sendEmail(); $this->scheduler->forceDelete(); } diff --git a/lang/en/texts.php b/lang/en/texts.php index cdaa431c3f11..daa40b7100ef 100644 --- a/lang/en/texts.php +++ b/lang/en/texts.php @@ -5033,6 +5033,9 @@ $LANG = array( 'vendors' => 'Vendors', 'product_sales' => 'Product Sales', 'sales_report_header' => 'User sales report for client/s :client from :start_date to :end_date', + 'customer_balance_report' => 'Customer balance report', + 'user_sales_report' => 'User sales report', + );