added some feature for accounting and price 7
This commit is contained in:
@@ -56,6 +56,61 @@ class TahesabController extends Controller
|
||||
return response()->json($tahesab);
|
||||
}
|
||||
|
||||
public function customerSyncStatus(Request $request): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
$total = Customer::whereNull('deleted_at')->count();
|
||||
$registered = Customer::whereNull('deleted_at')->whereNotNull('moshtari_code')->count();
|
||||
$unregistered = $total - $registered;
|
||||
|
||||
$query = Customer::whereNull('deleted_at')->whereNull('moshtari_code')
|
||||
->select('id', 'name', 'mobile', 'created_at');
|
||||
|
||||
if ($search = $request->input('search')) {
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('name', 'like', "%{$search}%")
|
||||
->orWhere('mobile', 'like', "%{$search}%");
|
||||
});
|
||||
}
|
||||
|
||||
$list = $query->orderBy('id')->paginate(20);
|
||||
|
||||
return response()->json([
|
||||
'total' => $total,
|
||||
'registered' => $registered,
|
||||
'unregistered'=> $unregistered,
|
||||
'list' => $list,
|
||||
]);
|
||||
}
|
||||
|
||||
public function syncPanelToTahesab(): \Illuminate\Http\JsonResponse
|
||||
{
|
||||
$customers = Customer::whereNull('deleted_at')
|
||||
->whereNull('moshtari_code')
|
||||
->select('id', 'name', 'mobile')
|
||||
->get();
|
||||
|
||||
$success = 0;
|
||||
$failed = 0;
|
||||
$errors = [];
|
||||
|
||||
foreach ($customers as $customer) {
|
||||
$result = $this->sync()->registerCustomer($customer);
|
||||
if ($result['ok'] ?? false) {
|
||||
$success++;
|
||||
} else {
|
||||
$failed++;
|
||||
$errors[] = ['name' => $customer->name, 'mobile' => $customer->mobile, 'error' => $result['message'] ?? ''];
|
||||
}
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'ok' => true,
|
||||
'success' => $success,
|
||||
'failed' => $failed,
|
||||
'errors' => $errors,
|
||||
]);
|
||||
}
|
||||
|
||||
public function retrySanad($id)
|
||||
{
|
||||
$tahesab = Tahesab::with('customer')->findOrFail($id);
|
||||
|
||||
Reference in New Issue
Block a user