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);
|
||||
|
||||
@@ -153,6 +153,8 @@ Route::middleware('auth:user')->group(function (){
|
||||
|
||||
Route::post('wallet/tahesab', [TahesabController::class, 'wallet']);
|
||||
Route::post('tahesab/table', [TahesabController::class, 'table']);
|
||||
Route::get('tahesab/customer-sync/status', [TahesabController::class, 'customerSyncStatus']);
|
||||
Route::post('tahesab/customer-sync/panel-to-tahesab', [TahesabController::class, 'syncPanelToTahesab']);
|
||||
Route::get('tahesab/{id}', [TahesabController::class, 'show']);
|
||||
Route::post('tahesab/{id}/retry', [TahesabController::class, 'retrySanad']);
|
||||
Route::post('customer/{id}/tahesab/register', [TahesabController::class, 'registerCustomer']);
|
||||
|
||||
Reference in New Issue
Block a user