08 2024
This commit is contained in:
parent
04d677d37a
commit
bfa3bb1df4
1191 changed files with 637397 additions and 10619 deletions
|
|
@ -7,8 +7,12 @@ use Storage;
|
|||
use App\User;
|
||||
use App\Services\Credit;
|
||||
use App\Models\UserCredit;
|
||||
use App\Services\MyPDFMerger;
|
||||
use Response;
|
||||
use App\Libraries\MyPDFMerger;
|
||||
use App\Models\UserCreditItem;
|
||||
use App\Models\UserSalesVolume;
|
||||
use App\Libraries\CreditDetailsPDF;
|
||||
use App\Services\BusinessPlan\TreeCalcBot;
|
||||
|
||||
class CreditRepository extends BaseRepository {
|
||||
|
||||
|
|
@ -87,7 +91,6 @@ class CreditRepository extends BaseRepository {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
private function makeUserCredit(){
|
||||
|
||||
$this->user_credit->net = 0;
|
||||
|
|
@ -127,4 +130,240 @@ class CreditRepository extends BaseRepository {
|
|||
return $user_credit_items;
|
||||
}
|
||||
|
||||
/*
|
||||
Erstellt einen detalierten Report zur Gutschrift
|
||||
Alle Postionen werden einzeln aufgelistet
|
||||
//$do ?= html, pdf
|
||||
*/
|
||||
public function create_report(UserCredit $user_credit, $do = 'html')
|
||||
{
|
||||
//collect all data
|
||||
$collection = new \stdClass();
|
||||
$collection->calc_bot = [];
|
||||
$collection->commission_shop = [];
|
||||
$collection->commission_payline = [];
|
||||
$collection->commission_growth_bonus = [];
|
||||
$collection->own_order = [];
|
||||
$collection->commission_registration = [];
|
||||
$collection->commission_credit = [];
|
||||
|
||||
|
||||
$dates = [];
|
||||
/* für jede Postion aus der Gutschrift nach Status */
|
||||
foreach($user_credit->user_credit_items as $user_credit_item){
|
||||
|
||||
$date = $user_credit_item->from_month.'-'.$user_credit_item->from_year;
|
||||
if(!isset($dates[$date])){
|
||||
$dates[$date] = ['year' => $user_credit_item->from_year, 'month' => $user_credit_item->from_month];
|
||||
}
|
||||
|
||||
/*
|
||||
//calc bot for the month year
|
||||
*/
|
||||
if(!isset($collection->calc_bot[$date])){
|
||||
$TreeCalcBot = new TreeCalcBot($user_credit_item->from_month, $user_credit_item->from_year, 'admin');
|
||||
$TreeCalcBot->initBusinesslUserDetail($user_credit->user);
|
||||
$TreeCalcBot->initStructureUser($user_credit->user->id);
|
||||
|
||||
$collection->calc_bot[$date] = $TreeCalcBot;
|
||||
}
|
||||
|
||||
/*
|
||||
status === 1 commission_shop
|
||||
Auswertung der Shopbestellungen vom User für einen Monat / Jahr
|
||||
Auslistung der Positonen / Gesamter Umsatz / Marge / Provision
|
||||
*/
|
||||
if($user_credit_item->status === 1){
|
||||
$user_sales_volumes = UserSalesVolume::where('user_id', $user_credit_item->user_id)
|
||||
->where('month', $user_credit_item->from_month)
|
||||
->where('year', $user_credit_item->from_year)
|
||||
->where('status', 2) //'shoporder', //hinzugefügt aus
|
||||
->orderBy('id', 'ASC')->get();
|
||||
|
||||
$user_sales_volumes_total = UserSalesVolume::where('user_id', $user_credit_item->user_id)
|
||||
->where('month', $user_credit_item->from_month)
|
||||
->where('year', $user_credit_item->from_year)
|
||||
->where('status', 2) //'shoporder', //hinzugefügt aus
|
||||
->orderBy('id', 'DESC')->first();
|
||||
|
||||
|
||||
|
||||
$obj = new \stdClass();
|
||||
$obj->user_sales_volumes = $user_sales_volumes;
|
||||
$obj->user_sales_volumes_total = $user_sales_volumes_total;
|
||||
$obj->user_credit_item = $user_credit_item;
|
||||
$collection->commission_shop[$date] = $obj;
|
||||
|
||||
/*
|
||||
UserSalesVolume::status
|
||||
4 => 'credit', //hinzugefügt aus //VE == status_turnover 2 shop verrechnung
|
||||
Listen der hinzufegügten Gutschriften vom User für einen Monat / Jahr
|
||||
*/
|
||||
$user_sales_volumes_credit = UserSalesVolume::where('user_id', $user_credit_item->user_id)
|
||||
->where('month', $user_credit_item->from_month)
|
||||
->where('year', $user_credit_item->from_year)
|
||||
->where('status', 4) //'credit', //hinzugefügt aus
|
||||
->where('status_turnover', 2) //VE shop
|
||||
->orderBy('id', 'ASC')->get();
|
||||
|
||||
$collection->commission_credit[$date] = $user_sales_volumes_credit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
status === 2 commission_payline
|
||||
Auswertung der Payline nach der Struktur vom User für einen Monat / Jahr
|
||||
Auslistung aller Berater mit Gesamter Umsatz / Provision / rang
|
||||
*/
|
||||
|
||||
/*
|
||||
status === 5 commission_growth_bonus
|
||||
Auswertung der Payline nach der Struktur vom User für einen Monat / Jahr
|
||||
Auslistung aller Berater mit Gesamter Umsatz / Provision / rang
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
nicht enhalten in der Gutschrift
|
||||
für alle Monate / Jahr die in der Gutschrift enthalten sind
|
||||
*/
|
||||
foreach($dates as $date => $dateObj){
|
||||
/*
|
||||
UserSalesVolume::status
|
||||
1 => 'advisor_order', own_order //hinzugefügt aus
|
||||
Listen der Beraterbestellungen vom User für einen Monat / Jahr
|
||||
*/
|
||||
$user_sales_volumes = UserSalesVolume::where('user_id', $user_credit_item->user_id)
|
||||
->where('month', $dateObj['month'])
|
||||
->where('year', $dateObj['year'])
|
||||
->where('status', 1) //'own_order', //hinzugefügt aus
|
||||
->orderBy('id', 'ASC')->get();
|
||||
|
||||
$credit_total_net = UserSalesVolume::where('user_id', $user_credit_item->user_id)
|
||||
->where('month', $dateObj['month'])
|
||||
->where('year', $dateObj['year'])
|
||||
->where('status', 1) //'own_order', //hinzugefügt aus
|
||||
->sum('total_net'); //sum('total_net');
|
||||
|
||||
$credit_total_points = UserSalesVolume::where('user_id', $user_credit_item->user_id)
|
||||
->where('month', $dateObj['month'])
|
||||
->where('year', $dateObj['year'])
|
||||
->where('status', 1) //'own_order', //hinzugefügt aus
|
||||
->sum('points'); //sum('points');
|
||||
|
||||
if($user_sales_volumes->count() > 0){
|
||||
$obj = new \stdClass();
|
||||
$obj->user_sales_volumes = $user_sales_volumes;
|
||||
$obj->credit_total_net = $credit_total_net;
|
||||
$obj->credit_total_points = $credit_total_points;
|
||||
$collection->own_order[$date] = $obj;
|
||||
}
|
||||
/*
|
||||
UserSalesVolume::status
|
||||
5 => 'registration', //hinzugefügt aus
|
||||
Listen der Gutschriften aus Reg vom User für einen Monat / Jahr
|
||||
Enthält nur Punkte wird separat aufgeführt
|
||||
turnover = immer E / 1 verrechnung mit Eigenem Umsatz
|
||||
*/
|
||||
|
||||
$user_sales_volumes = UserSalesVolume::where('user_id', $user_credit_item->user_id)
|
||||
->where('month', $dateObj['month'])
|
||||
->where('year', $dateObj['year'])
|
||||
->where('status', 5) //'registration', //hinzugefügt aus
|
||||
->orderBy('id', 'ASC')->get();
|
||||
|
||||
$credit_total_net = UserSalesVolume::where('user_id', $user_credit_item->user_id)
|
||||
->where('month', $dateObj['month'])
|
||||
->where('year', $dateObj['year'])
|
||||
->where('status', 5) //'registration', //hinzugefügt aus
|
||||
->sum('total_net'); //sum('total_net');
|
||||
|
||||
$credit_total_points = UserSalesVolume::where('user_id', $user_credit_item->user_id)
|
||||
->where('month', $dateObj['month'])
|
||||
->where('year', $dateObj['year'])
|
||||
->where('status', 5) //'registration', //hinzugefügt aus
|
||||
->sum('points'); //sum('points');
|
||||
|
||||
if($user_sales_volumes->count() > 0){
|
||||
$obj = new \stdClass();
|
||||
$obj->user_sales_volumes = $user_sales_volumes;
|
||||
$obj->credit_total_net = $credit_total_net;
|
||||
$obj->credit_total_points = $credit_total_points;
|
||||
$collection->commission_registration[$date] = $obj;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
//need this?
|
||||
$user_credit_item->status = 3; //credit_added
|
||||
$user_credit_item->status = 4; //commission
|
||||
*/
|
||||
|
||||
$data = [
|
||||
'dates' => $dates,
|
||||
'user_credit' => $user_credit,
|
||||
'collection' => $collection,
|
||||
];
|
||||
if($do === 'html'){
|
||||
return view('admin.payment.credit_detail', $data);
|
||||
}
|
||||
|
||||
if($do === 'pdf'){
|
||||
|
||||
|
||||
$dir = Credit::getCreditDetailStorageDir($user_credit->date);
|
||||
if(!Storage::disk('public')->exists( $dir )){
|
||||
Storage::disk('public')->makeDirectory($dir); //creates directory
|
||||
}
|
||||
$path = Storage::disk('public')->getAdapter()->getPathPrefix();
|
||||
$filename = Credit::makeCreditDetailFilename($user_credit->full_number);
|
||||
|
||||
$pdf = new CreditDetailsPDF('pdf.credit_details');
|
||||
//return $pdf->create($data, 'credit_details.pdf', 'stream');
|
||||
|
||||
$pdf->create($data, $filename, 'save', $path.$dir);
|
||||
|
||||
|
||||
/*$pdf = PDF::loadView('pdf.credit', $data);
|
||||
$pdf->setPaper('A4', 'portrait');
|
||||
$pdf->save($path.$dir.$filename);*/
|
||||
|
||||
$pdfMerger = new MyPDFMerger();
|
||||
$pdfMerger->addPDF($path.$dir.$filename);
|
||||
$file = $pdfMerger->myMerge('string', $filename, 'template_report_de');
|
||||
Storage::disk('public')->put($dir.$filename, $file);
|
||||
$path = $dir.$filename;
|
||||
//$file = Storage::disk('public')->get($path);
|
||||
$mime = Storage::disk('public')->mimeType($path);
|
||||
|
||||
return Response::make($file, 200)
|
||||
->header("Content-Type", $mime)
|
||||
->header('Content-disposition','inline; filename="'.$filename.'"');
|
||||
|
||||
|
||||
//return $dir.$filename;
|
||||
/*
|
||||
$dir = Credit::getCreditStorageDir($credit_date);
|
||||
if(!Storage::disk('public')->exists( $dir )){
|
||||
Storage::disk('public')->makeDirectory($dir); //creates directory
|
||||
}
|
||||
$path = Storage::disk('public')->getAdapter()->getPathPrefix();
|
||||
|
||||
$filename = Credit::makeCreditFilename($credit_number);
|
||||
|
||||
$pdf->save($path.$dir.$filename);
|
||||
|
||||
$pdfMerger = new MyPDFMerger();
|
||||
$pdfMerger->addPDF($path.$dir.$filename);
|
||||
$file = $pdfMerger->myMerge('string', $filename, 'template_invoice_de');
|
||||
Storage::disk('public')->put($dir.$filename, $file);
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue