function erp_ac_get_expenses_last_30_days() { $transaction = new \WeDevs\ERP\Accounting\Model\Transaction(); $journal = new \WeDevs\ERP\Accounting\Model\Journal(); $db = new \WeDevs\ORM\Eloquent\Database(); $last_date = current_time('mysql'); $first_date = date('Y-m-d', strtotime('-30 day', strtotime($last_date))); $transaction_res = $transaction->select(array($db->raw('SUM(trans_total) as trans_total'))); $transaction_res = $transaction_res->where(function ($condition) use($first_date, $last_date) { $condition->where('issue_date', '>', $first_date); $condition->where('form_type', '=', 'payment_voucher'); $condition->where('status', '=', 'paid'); }); $due = $transaction_res->pluck('trans_total'); return intval($due); }
function erp_ac_bank_credit_total_amount($bank_id) { $db = new \WeDevs\ORM\Eloquent\Database(); $dc = []; $dc['debit'] = \WeDevs\ERP\Accounting\Model\Journal::select(array($db->raw('SUM(debit) as debit_sum')))->where('ledger_id', $bank_id)->pluck('debit_sum'); $dc['credit'] = \WeDevs\ERP\Accounting\Model\Journal::select(array($db->raw('SUM(credit) as credit_sum')))->where('ledger_id', $bank_id)->pluck('credit_sum'); return $dc; }
/** * Get newxt month leave request approved list * * @since 0.1 * * @return array */ function erp_hr_get_next_month_leave_list() { $db = new \WeDevs\ORM\Eloquent\Database(); return erp_array_to_object(\WeDevs\ERP\HRM\Models\Leave_request::select('user_id', 'start_date', 'end_date')->where($db->raw("DATE_FORMAT( `start_date`, '%m %Y' )"), \Carbon\Carbon::today()->addMonth(1)->format('m Y'))->where('status', 1)->get()->toArray()); }
/** * Get next seven days birthday * * @since 0.1 * * @return object [user_id, date_of_birth] */ function erp_hr_get_next_seven_days_birthday() { $db = new \WeDevs\ORM\Eloquent\Database(); return erp_array_to_object(\WeDevs\ERP\HRM\Models\Employee::select(array('user_id', 'date_of_birth'))->where($db->raw("DATE_FORMAT( `date_of_birth`, '%m %d' )"), '>', \Carbon\Carbon::today()->format('m d'))->where($db->raw("DATE_FORMAT( `date_of_birth`, '%m %d' )"), '<=', \Carbon\Carbon::tomorrow()->addWeek()->format('m d'))->get()->toArray()); }
/** * Get all customer feeds * * @since 1.0 * * @param integer $customer_id * * @return array */ function erp_crm_get_customer_activity($postdata) { $feeds = []; $db = new \WeDevs\ORM\Eloquent\Database(); $results = \WeDevs\ERP\CRM\Models\Activity::select(['*', $db->raw('MONTHNAME(`created_at`) as feed_month, YEAR( `created_at` ) as feed_year')])->where('user_id', $postdata['customer_id'])->with(['contact', 'created_by' => function ($query) { $query->select('ID', 'user_nicename', 'user_email', 'user_url', 'display_name'); }])->orderBy('created_at', 'DESC')->skip($postdata['offset'])->take($postdata['limit'])->get()->toArray(); foreach ($results as $key => $value) { $value['extra'] = json_decode(base64_decode($value['extra']), true); if (isset($value['extra']['invite_contact']) && count($value['extra']['invite_contact']) > 0) { foreach ($value['extra']['invite_contact'] as $user_id) { $value['extra']['invited_user'][] = ['id' => $user_id, 'name' => get_the_author_meta('display_name', $user_id)]; } } else { $value['extra']['invited_user'] = []; } unset($value['extra']['invite_contact']); $value['created_by']['avatar'] = get_avatar_url($value['created_by']['ID']); $value['created_date'] = date('Y-m-d', strtotime($value['created_at'])); $value['created_timeline_date'] = date('Y-m', strtotime($value['created_at'])); $feeds[] = $value; } return $feeds; }