This commit is contained in:
Shohrat 2023-12-22 01:30:58 +05:00
parent d2a393e765
commit c8ec8972ab
7 changed files with 94 additions and 39 deletions

View File

@ -39,11 +39,9 @@ class Order extends ComponentBase
$orders = OrderModel::with(["client", "shipping"])
->withCount(['order_items as order_all_amount' => function ($query) {
$query->select(DB::raw('sum(amount)'));
}])
->withCount(['order_items as qty'])
->withCount(['order_items as order_all_price' => function ($query) {
$query->select(DB::raw('sum(price) * sum(amount)'));
$query->select(DB::raw('sum(price) * sum(amount) / qty'));
}])
->withCount(['payment as all_payments' => function ($query) {
$query->select(DB::raw('sum(amount)'));
@ -87,6 +85,17 @@ class Order extends ComponentBase
$allPaid += $ordersFiltered[$x]->all_payments;
$allNotPaid += ($ordersFiltered[$x]->order_all_price - $ordersFiltered[$x]->all_payments);
$mustPay = '';
$mustPayCalc = number_format(($ordersFiltered[$x]->order_all_price - $ordersFiltered[$x]->all_payments), 2);
if($mustPayCalc < 0){
$mustPay = 'artykmaç '.abs($mustPayCalc).' $';
}else if($mustPayCalc == 0){
$mustPay = '';
} else{
$mustPay = $mustPayCalc.' $';
}
$html_data .= '<tr>
<td style="font-weight: bold;">' . ($x + 1) . '</td>
<td><a href="/order-detail/' . $ordersFiltered[$x]->id . '" style="font-weight: bold;">Sargyt #' . $ordersFiltered[$x]->id . '</a></td>
@ -99,7 +108,7 @@ class Order extends ComponentBase
<td><span class="badge badge-soft-success"
style="font-size: 14px;">' . number_format($ordersFiltered[$x]->all_payments) . ' $</span>
</td>
<td><a href="#" class="badge badge-soft-danger" style="font-size: 14px;">' . number_format($ordersFiltered[$x]->order_all_price - $ordersFiltered[$x]->all_payments) . ' $</a>
<td><a href="#" class="badge badge-soft-danger" style="font-size: 14px;">' . $mustPay . '</a>
</td>
<td>' . $ordersFiltered[$x]->created_at->format('d.m.Y') . '</td>
<td>' . $ordersFiltered[$x]->note . '</td>
@ -227,9 +236,9 @@ class Order extends ComponentBase
$html_data .= '<tr>
<td style="font-weight: bold;">' . ($x + 1) . '</td>
<td><a href="/orders/transport/loaded/' . $shippingTransportsFiltered[$x]->shipping->order->id . '/'.$shippingTransportsFiltered[$x]->id.'" style="font-weight: bold;">' . $transportTitle . '</a></td>
<td><a href="/orders/transport/loaded/' . $shippingTransportsFiltered[$x]->shipping->order_id . '/'.$shippingTransportsFiltered[$x]->id.'" style="font-weight: bold;">' . $transportTitle . '</a></td>
<td>' . $shippingTransportsFiltered[$x]->transport_no . '</td>
<td><a href="/order-detail/' . $shippingTransportsFiltered[$x]->shipping->order->id . '" style="font-weight: bold;">Sargyt #' . $shippingTransportsFiltered[$x]->shipping->order->id . '</a></td>
<td><a href="/order-detail/' . $shippingTransportsFiltered[$x]->shipping->order_id . '" style="font-weight: bold;">Sargyt #' . $shippingTransportsFiltered[$x]->shipping->order_id . '</a></td>
<td>' . $shippingTransportsFiltered[$x]->place_now . '</td>
@ -263,6 +272,9 @@ class Order extends ComponentBase
->withCount(['order_items as order_all_price' => function ($query) {
$query->select(DB::raw('sum(price) * sum(amount) / qty'));
}])
->withCount(['payment as all_payments' => function ($query) {
$query->select(DB::raw('sum(amount)'));
}])
->orderBy('id', 'DESC')
->get();
@ -276,6 +288,17 @@ class Order extends ComponentBase
$editBtn = $crudOrderq ? '<a href="#" data-request="onDeleteOrder" data-request-confirm="Sargyt #' . $orderDatas[$x]->id . ' pozmak isleýäňizmi?" data-request-data="orderId: ' . $orderDatas[$x]->id . '" style="color: darkred;font-weight: bold;">POZ</a>' : '';
}
$mustPay = '';
$mustPayCalc = number_format(($orderDatas[$x]->order_all_price - $orderDatas[$x]->all_payments), 2);
if($mustPayCalc < 0){
$mustPay = 'artykmaç '.abs($mustPayCalc).' $';
}else if($mustPayCalc == 0){
$mustPay = '';
} else{
$mustPay = $mustPayCalc.' $';
}
$html_data .= '<tr>
<td style="font-weight: bold;">' . ($x + 1) . '</td>
<td><a href="/order-detail/' . $orderDatas[$x]->id . '" style="font-weight: bold;">Sargyt #' . $orderDatas[$x]->id . '</a></td>
@ -288,7 +311,7 @@ class Order extends ComponentBase
<td><span class="badge badge-soft-success"
style="font-size: 14px;">' . number_format($orderDatas[$x]->all_payments) . ' $</span>
</td>
<td><a href="#" class="badge badge-soft-danger" style="font-size: 14px;">' . number_format($orderDatas[$x]->order_all_price - $orderDatas[$x]->all_payments) . ' $</a>
<td><a href="#" class="badge badge-soft-danger" style="font-size: 14px;">' . $mustPay . '</a>
</td>
<td>' . $orderDatas[$x]->created_at->format('d.m.Y') . '</td>
<td>' . $orderDatas[$x]->note . '</td>

View File

@ -136,10 +136,10 @@ class OrderItem extends ComponentBase
$loadedAmount = ModelsLoadTransport::where('order_item_id', $orderItems[$x]->id)->sum('loaded_amount');
if($loadedAmount > $orderItems[$x]->amount){
$diffLoaded = ($loadedAmount - $orderItems[$x]->amount);
$diffLoaded = number_format(($loadedAmount - $orderItems[$x]->amount), 2);
$status = '<font style="color: darkgreen;">Tamamlandy (+'.$diffLoaded.')</font';
}else if($loadedAmount < $orderItems[$x]->amount){
$diffLoaded = ($orderItems[$x]->amount - $loadedAmount);
$diffLoaded = number_format(($orderItems[$x]->amount - $loadedAmount), 2);
$status = '<font style="color: darkred;">Ýetmezçilik (-'.$diffLoaded.')</font';
}else if($loadedAmount == $orderItems[$x]->amount){
$status = '<font style="color: darkgreen;">Tamalandy</font';

View File

@ -35,20 +35,16 @@ function onStart() {
$action = Romanah\Gokbakja\Models\RulonAction::select('romanah_gokbakja_rulon_action.*')
->with('product')
->whereYear('created_at', $year)
->whereMonth('created_at', $this["month"])
->whereHas('product', function($qq) use($rulonProds, $x){
$qq->where('gram', $rulonProds[$x]->gram)->where('width', $rulonProds[$x]->width);
$qq->where('gram', $rulonProds[$x]->gram)->where('width', $rulonProds[$x]->width)->whereYear('date', $year)->whereMonth('date', $this["month"]);
})
->sum('amount');
$actionIn = Romanah\Gokbakja\Models\RulonAction::select('romanah_gokbakja_rulon_action.*')
->with('product')
->where('type', 'inbox')
->whereYear('created_at', $year)
->whereMonth('created_at', $this["month"])
->whereHas('product', function($qq) use($rulonProds, $x){
$qq->where('gram', $rulonProds[$x]->gram)->where('width', $rulonProds[$x]->width);
$qq->where('gram', $rulonProds[$x]->gram)->where('width', $rulonProds[$x]->width)->whereYear('date', $year)->whereMonth('date', $this["month"]);
})
->sum('amount');
@ -56,10 +52,8 @@ function onStart() {
$actionOut = Romanah\Gokbakja\Models\RulonAction::select('romanah_gokbakja_rulon_action.*')
->with('product')
->where('type', 'outbox')
->whereYear('created_at', $year)
->whereMonth('created_at', $this["month"])
->whereHas('product', function($qq) use($rulonProds, $x){
$qq->where('gram', $rulonProds[$x]->gram)->where('width', $rulonProds[$x]->width);
$qq->where('gram', $rulonProds[$x]->gram)->where('width', $rulonProds[$x]->width)->whereYear('date', $year)->whereMonth('date', $this["month"]);
})
->sum('amount');
@ -87,20 +81,16 @@ function onStart() {
$action = Romanah\Gokbakja\Models\RulonAction::select('romanah_gokbakja_rulon_action.*')
->with('product')
->whereYear('created_at', $currentDate->year)
->whereMonth('created_at', $this["month"])
->whereHas('product', function($qq) use($rulonProds, $x){
$qq->where('gram', $rulonProds[$x]->gram)->where('width', $rulonProds[$x]->width);
->whereHas('product', function($qq) use($rulonProds, $x, $currentDate){
$qq->where('gram', $rulonProds[$x]->gram)->where('width', $rulonProds[$x]->width)->whereYear('date', $currentDate->year)->whereMonth('date', $this["month"]);
})
->sum('amount');
$actionIn = Romanah\Gokbakja\Models\RulonAction::select('romanah_gokbakja_rulon_action.*')
->with('product')
->where('type', 'inbox')
->whereYear('created_at', $currentDate->year)
->whereMonth('created_at', $this["month"])
->whereHas('product', function($qq) use($rulonProds, $x){
$qq->where('gram', $rulonProds[$x]->gram)->where('width', $rulonProds[$x]->width);
->whereHas('product', function($qq) use($rulonProds, $x, $currentDate){
$qq->where('gram', $rulonProds[$x]->gram)->where('width', $rulonProds[$x]->width)->whereYear('date', $currentDate->year)->whereMonth('date', $this["month"]);
})
->sum('amount');
@ -108,10 +98,8 @@ function onStart() {
$actionOut = Romanah\Gokbakja\Models\RulonAction::select('romanah_gokbakja_rulon_action.*')
->with('product')
->where('type', 'outbox')
->whereYear('created_at', $currentDate->year)
->whereMonth('created_at', $this["month"])
->whereHas('product', function($qq) use($rulonProds, $x){
$qq->where('gram', $rulonProds[$x]->gram)->where('width', $rulonProds[$x]->width);
->whereHas('product', function($qq) use($rulonProds, $x, $currentDate){
$qq->where('gram', $rulonProds[$x]->gram)->where('width', $rulonProds[$x]->width)->whereYear('date', $currentDate->year)->whereMonth('date', $this["month"]);
})
->sum('amount');

View File

@ -26,7 +26,16 @@ function onStart(){
if($count > 0){
$this["all"] = ($this["order"]->order_all_amount * $this["order"]->order_all_price) / $count;
}
$this["orderItems"] = Romanah\Gokbakja\Models\OrderItem::where("order_id", $orderId)->orderBy("id", "DESC")->with(["type", "size", "color"])->get();
$orderItems = Romanah\Gokbakja\Models\OrderItem::where("order_id", $orderId)->orderBy("id", "DESC")->with(["type", "size", "color"])->get();
$sumOfPrice = 0;
for ($x = 0; $x < count($orderItems); $x++) {
$sumOfPrice = ($sumOfPrice + ($orderItems[$x]->amount * $orderItems[$x]->price));
}
$this["sumOfPrice"] = $sumOfPrice;
$this["sizes"] = Romanah\Gokbakja\Models\BagSize::get();
$this["types"] = Romanah\Gokbakja\Models\BagType::get();
@ -184,7 +193,7 @@ function onStart(){
</div>
{% partial "order/item_header" contract_no=order.contract_no orderId=order.id clientName=order.client.name
allAmount=order.order_all_amount allPrice=order.order_all_price all=all %}
allAmount=order.order_all_amount allPrice=order.order_all_price all=sumOfPrice %}
<div class="card">

View File

@ -29,6 +29,16 @@ function onStart(){
$this["orderItems"] = Romanah\Gokbakja\Models\OrderItem::where("order_id", $orderId)->get();
$orderItems = Romanah\Gokbakja\Models\OrderItem::where("order_id", $orderId)->orderBy("id", "DESC")->with(["type", "size", "color"])->get();
$sumOfPrice = 0;
for ($x = 0; $x < count($orderItems); $x++) {
$sumOfPrice = ($sumOfPrice + ($orderItems[$x]->amount * $orderItems[$x]->price));
}
$this["sumOfPrice"] = $sumOfPrice;
$this["transports"] = Romanah\Gokbakja\Models\ShippingTransport::where("shipping_id", $this["order"]->shipping_id)->with('shipping.order')->with('order_item')->orderBy("id", "DESC")->get();
@ -134,7 +144,7 @@ function onStart(){
</div>
{% partial "order/item_header" contract_no=order.contract_no orderId=order.id clientName=order.client.name
allAmount=order.order_all_amount allPrice=order.order_all_price all=all %}
allAmount=order.order_all_amount allPrice=order.order_all_price all=sumOfPrice %}
<div class="card">

View File

@ -24,13 +24,31 @@ function onStart(){
$count = Romanah\Gokbakja\Models\OrderItem::where("order_id", $orderId)->count();
if($count > 0){
$this["all"] = ($this["order"]->order_all_amount * $this["order"]->order_all_price) / $count;
$this["all"] = ($this["order"]->order_all_amount * $this["order"]->order_all_price) / $count;
}
$this["payments"] = Romanah\Gokbakja\Models\Payment::where("order_id", $orderId)->with('order')->orderBy("id", "DESC")->get();
$this["allPaid"] = Romanah\Gokbakja\Models\Payment::where("order_id", $orderId)->sum("amount");
$this["allNot"] = ($this["all"] - $this["allPaid"]);
$orderItems = Romanah\Gokbakja\Models\OrderItem::where("order_id", $orderId)->orderBy("id", "DESC")->with(["type", "size", "color"])->get();
$sumOfPrice = 0;
for ($x = 0; $x < count($orderItems); $x++) {
$sumOfPrice = ($sumOfPrice + ($orderItems[$x]->amount * $orderItems[$x]->price));
}
$this["sumOfPrice"] = $sumOfPrice;
$allNot = ($sumOfPrice - $this["allPaid"]);
$this["allNot"] = "";
if($allNot < 0){
$this["allNot"] = abs($allNot).' $ artyk tölenen';
}else{
$this["allNot"] = 'Bergisi: '.$allNot.' $';
}
}
?>
@ -125,7 +143,7 @@ function onStart(){
</div>
{% partial "order/item_header" contract_no=order.contract_no orderId=order.id clientName=order.client.name
allAmount=order.order_all_amount allPrice=order.order_all_price all=all %}
allAmount=order.order_all_amount allPrice=order.order_all_price all=sumOfPrice %}
<div class="card">
@ -134,8 +152,15 @@ function onStart(){
<div class="row">
<div class="col-md-6">
<h3 class="card-title" style="font-size: 22px;color: #1e2038;">Sargyt Töleg Maglumatlary</h3>
<p class="card-title-desc" style="color: #00577f;font-size: 17px;margin-bottom: 0px;" >Tölemeli Mukdary: {{sumOfPrice|number_format}} $</p>
<hr>
<p class="card-title-desc" style="color: darkgreen;font-size: 17px;margin-bottom: 0px;" id="all_payment">Jemi Tölenen Töleg: {{allPaid|number_format}} $</p>
<p class="card-title-desc" style="color: darkred;font-size: 17px;" id="all_not">Bergisi: {{allNot|number_format}} $</p>
<p class="card-title-desc" style="color: darkred;font-size: 17px;" id="all_not">
{{allNot}}
</p>
</div>
<div class="col-md-6" style="text-align: right;">
{% if crudOrders %}

View File

@ -57,7 +57,7 @@
</div>
<div class="flex-grow-1 align-self-center overflow-hidden">
<h5 id="allPrice">Jemi Bahasy: {{all|number_format}} $</h5>
<p class="text-muted mb-0" id="all">{{allPrice}} $</p>
<!-- <p class="text-muted mb-0" id="all">{{allPrice}} $</p> -->
</div>
</div>
</div>