WIP #1
@ -35,7 +35,7 @@ public function index(Request $request)
|
||||
]);
|
||||
}
|
||||
|
||||
public function CloseCashClose($id)
|
||||
public function closeCashClose($id)
|
||||
{
|
||||
$today = now()->format('Y-m-d');
|
||||
|
||||
@ -50,7 +50,6 @@ public function CloseCashClose($id)
|
||||
$cashClose->update([
|
||||
'income' => $totalSales,
|
||||
'balance' => $totalSales - $cashClose->exit,
|
||||
'payment_methods' => $paymentMethods,
|
||||
'status' => 'closed',
|
||||
'close_date' => $today,
|
||||
]);
|
||||
@ -94,28 +93,34 @@ public function report($id)
|
||||
->get();
|
||||
|
||||
// Reporte detallado de ventas
|
||||
$detailedSales = DB::table('sales')
|
||||
->join('clients', 'sales.client_id', '=', 'clients.id')
|
||||
->join('sale_items', 'sales.id', '=', 'sale_items.sale_id')
|
||||
->join('packages', 'sale_items.package_id', '=', 'packages.id')
|
||||
->join('sim_cards', 'sale_items.sim_card_id', '=', 'sim_cards.id')
|
||||
->where('sales.cash_close_id', $id)
|
||||
->select(
|
||||
DB::raw("CONCAT(clients.name, ' ', clients.paternal, ' ', clients.maternal) as nombre_comprador"),
|
||||
'sim_cards.iccid as id_sim',
|
||||
'sim_cards.msisdn as numero_asignado',
|
||||
'packages.name as paquete',
|
||||
'packages.price as costo',
|
||||
'sales.payment_method as medio_pago'
|
||||
)
|
||||
->orderBy('sales.id', 'desc')
|
||||
->get();
|
||||
$detailedSales = SaleItem::whereHas('sale', function($query) use ($id) {
|
||||
$query->where('cash_close_id', $id);
|
||||
})
|
||||
->with([
|
||||
'sale.client:id,name,paternal,maternal',
|
||||
'sale:id,client_id,payment_method',
|
||||
'simCard:id,iccid,msisdn',
|
||||
'package:id,name,price'
|
||||
])
|
||||
->orderBy('id', 'asc')
|
||||
->paginate(config('app.pagination'))
|
||||
->through(function($item) {
|
||||
return [
|
||||
'nombre_comprador' => $item->sale->client->full_name,
|
||||
'id_sim' => $item->simCard->iccid,
|
||||
'numero_asignado' => $item->simCard->msisdn,
|
||||
'paquete' => $item->package->name,
|
||||
'costo' => $item->package->price,
|
||||
'medio_pago' => $item->sale->payment_method
|
||||
];
|
||||
});
|
||||
|
||||
|
||||
return ApiResponse::OK->response([
|
||||
'cash_close' => $cashClose,
|
||||
'ventas por paquete' => $packageStats,
|
||||
'ventas por duracion' => $durationStats,
|
||||
'ventas detalladas' => $detailedSales,
|
||||
'ventas_paquete' => $packageStats,
|
||||
'ventas_duracion' => $durationStats,
|
||||
'ventas_detalladas' => $detailedSales,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,10 +12,7 @@ class CashClose extends Model
|
||||
'balance',
|
||||
'income',
|
||||
'exit',
|
||||
'expected_balance',
|
||||
'difference',
|
||||
'close_date',
|
||||
'notes',
|
||||
'status',
|
||||
'user_id',
|
||||
];
|
||||
@ -24,8 +21,6 @@ class CashClose extends Model
|
||||
'balance' => 'decimal:2',
|
||||
'income' => 'decimal:2',
|
||||
'exit' => 'decimal:2',
|
||||
'expected_balance' => 'decimal:2',
|
||||
'difference' => 'decimal:2',
|
||||
'close_date' => 'date',
|
||||
];
|
||||
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
*/
|
||||
|
||||
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
@ -40,4 +41,11 @@ public function simCards()
|
||||
->withPivot('assigned_at', 'released_at', 'is_active')
|
||||
->withTimestamps();
|
||||
}
|
||||
|
||||
public function fullName(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: fn () => $this->name . ' ' . $this->paternal . ' ' . $this->maternal,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user