whereBetween('created_at', [$start, $end])->get(); if (count($patient_category_invoices)) { foreach ($patient_category_invoices as $single_record) { $items_array = explode(",", $single_record->items_ids); $tag_id = $single_record->tag_id; $income_accounts_array = $cost_of_goods_account_array = $inventory_account_array = []; for ($i = 0; $i < count($items_array); $i++) { //Consultations / Services if ($tag_id == 6 || $tag_id == 8 || $tag_id == 7 || $tag_id == 10) { $income_account = get_name($items_array[$i], 'id', 'account_id', 'services'); $income_account = is_numeric($income_account) ? $income_account : 7; $income_accounts_array[] = $income_account; } //Drugs / Treatments elseif ($tag_id == 3 || $tag_id == 1) { $income_account = get_name($items_array[$i], 'id', 'account_id', 'drugs'); $income_account = is_numeric($income_account) ? $income_account : 4; $income_accounts_array[] = $income_account; $inventory_account = get_name($items_array[$i], 'id', 'inventory_account', 'drugs'); $inventory_account_array[] = $inventory_account; $cost_of_goods_account = get_name($items_array[$i], 'id', 'cost_of_goods_account', 'drugs'); $cost_of_goods_account_array[] = $cost_of_goods_account; $cost_price_array[$i] = get_latest_inventory_cost_price($items_array[$i], 1, Carbon::today()->toDateString()); } //Sundries elseif ($tag_id == 5) { $income_account = get_name($items_array[$i], 'id', 'account_id', 'sundries'); $income_account = is_numeric($income_account) ? $income_account : 12; $income_accounts_array[] = $income_account; $inventory_account = get_name($items_array[$i], 'id', 'inventory_account', 'sundries'); $inventory_account_array[] = $inventory_account; $cost_of_goods_account = get_name($items_array[$i], 'id', 'cost_of_goods_account', 'sundries'); $cost_of_goods_account_array[] = $cost_of_goods_account; $cost_price_array[$i] = get_latest_inventory_cost_price($items_array[$i], 2, Carbon::today()->toDateString()); } //Investigations elseif ($tag_id == 2) { $income_account = get_name($items_array[$i], 'id', 'account_id', 'investigations'); $income_account = is_numeric($income_account) ? $income_account : 11; $income_accounts_array[] = $income_account; } //Procedures elseif ($tag_id == 4) { $income_account = get_name($items_array[$i], 'id', 'account_id', 'procedures'); $income_account = is_numeric($income_account) ? $income_account : 8; $income_accounts_array[] = $income_account; } } $income_accounts_string = is_null($income_accounts_array) ? "" : implode(',', $income_accounts_array); $cost_of_goods_accounts_string = is_null($cost_of_goods_account_array) ? null : implode(',', $cost_of_goods_account_array); $inventory_accounts_string = is_null($inventory_account_array) ? null : implode(',', $inventory_account_array); $existing_patient_category_invoice = PatientCategoryInvoice::withTrashed()->find($single_record->id); $existing_patient_category_invoice->income_account = $income_accounts_string; if ($tag_id == 3 || $tag_id == 1 || $tag_id == 5) { $existing_patient_category_invoice->cost_of_goods_account = $cost_of_goods_accounts_string; $existing_patient_category_invoice->inventory_account = $inventory_accounts_string; } $existing_patient_category_invoice->update(); } } $equities = Equity::all(); foreach ($equities as $equity) { $equity->transaction_date = $equity->created_at; $equity->update(); //pick the equity and update it with the journal date if it was journaled if (str_contains($equity, 'Journal (')) { $journal_number = getStringBetweenCharacters($equity->name,"(",")"); $journal = Journal::find($journal_number); if($journal){ //update the equity record's transaction date with the date it was journaled $equity->transaction_date = $journal->journal_date; $equity->update(); } } } } }