';
$totalTaxPrice = 0;
$taxesData = [];
$items = [];
for ($i = 1; $i <= 3; $i++) {
$item = new \stdClass();
$item->name = 'Item ' . $i;
$item->quantity = 1;
$item->tax = 5;
$item->discount = 50;
$item->price = 100;
$taxes = [
'Tax 1',
'Tax 2',
];
$itemTaxes = [];
foreach ($taxes as $k => $tax) {
$taxPrice = 10;
$totalTaxPrice += $taxPrice;
$itemTax['name'] = 'Tax ' . $k;
$itemTax['rate'] = '10 %';
$itemTax['price'] = '$10';
$itemTaxes[] = $itemTax;
if (array_key_exists('Tax ' . $k, $taxesData)) {
$taxesData['Tax ' . $k] = $taxesData['Tax 1'] + $taxPrice;
} else {
$taxesData['Tax ' . $k] = $taxPrice;
}
}
$item->itemTax = $itemTaxes;
$items[] = $item;
}
$quotation->quotation_id = 1;
$quotation->issue_date = date('Y-m-d H:i:s');
$quotation->itemData = $items;
$quotation->totalTaxPrice = 60;
$quotation->totalQuantity = 3;
$quotation->totalRate = 300;
$quotation->totalDiscount = 10;
$quotation->taxesData = $taxesData;
$quotation->created_by = $objUser->creatorId();
$preview = 1;
$color = '#' . $color;
$font_color = Utility::getFontColor($color);
$logo = asset(Storage::url('uploads/logo/'));
$company_logo = Utility::getValByName('company_logo_dark');
$settings_data = \App\Models\Utility::settingsById($quotation->created_by);
$quotation_logo = isset($settings_data['quotation_logo']) ? $settings_data['quotation_logo'] : '';
if (isset($quotation_logo) && !empty($quotation_logo)) {
$img = Utility::get_file('quotation_logo/') . $quotation_logo;
} else {
$img = asset($logo . '/' . (isset($company_logo) && !empty($company_logo) ? $company_logo : 'logo-dark.png'));
}
return view('quotation.templates.' . $template, compact('quotation', 'preview', 'color', 'img', 'settings', 'customer', 'font_color', 'quotationPayment'));
}
public function saveQuotationTemplateSettings(Request $request)
{
$post = $request->all();
unset($post['_token']);
if (isset($post['quotation_template']) && (!isset($post['quotation_color']) || empty($post['quotation_color']))) {
$post['quotation_color'] = "ffffff";
}
if ($request->quotation_logo) {
$dir = 'quotation_logo/';
$quotation_logo = \Auth::user()->id . '_quotation_logo.png';
$validation = [
'mimes:' . 'png',
'max:' . '20480',
];
$path = Utility::upload_file($request, 'quotation_logo', $quotation_logo, $dir, $validation);
if ($path['flag'] == 0) {
return redirect()->back()->with('error', __($path['msg']));
}
$post['quotation_logo'] = $quotation_logo;
}
foreach ($post as $key => $data) {
\DB::insert(
'insert into settings (`value`, `name`,`created_by`) values (?, ?, ?) ON DUPLICATE KEY UPDATE `value` = VALUES(`value`) ', [
$data,
$key,
\Auth::user()->creatorId(),
]
);
}
return redirect()->back()->with('success', __('Quotation Setting updated successfully'));
}
public function printView(Request $request)
{
$sess = session()->get('pos');
$user = Auth::user();
$settings = Utility::settings();
$customer = Customer::where('name', '=', $request->vc_name)->where('created_by', $user->creatorId())->first();
$warehouse = warehouse::where('id', '=', $request->warehouse_name)->where('created_by', $user->creatorId())->first();
$details = [
'pos_id' => $user->quotationNumberFormat($this->quotationNumber()),
'customer' => $customer != null ? $customer->toArray() : [],
'warehouse' => $warehouse != null ? $warehouse->toArray() : [],
'user' => $user != null ? $user->toArray() : [],
'date' => date('Y-m-d'),
'pay' => 'show',
];
if (!empty($details['customer'])) {
$warehousedetails = '' . ucfirst($details['warehouse']['name']) . '';
$details['customer']['billing_state'] = $details['customer']['billing_state'] != '' ? ", " . $details['customer']['billing_state'] : '';
$details['customer']['shipping_state'] = $details['customer']['shipping_state'] != '' ? ", " . $details['customer']['shipping_state'] : '';
$customerdetails = '' . ucfirst($details['customer']['name']) . '
' . $details['customer']['billing_phone'] . '
' . '' . $details['customer']['billing_address'] . '
' . '' . $details['customer']['billing_city'] . $details['customer']['billing_state'] . '
' . '' . $details['customer']['billing_country'] . '
' . '' . $details['customer']['billing_zip'] . '
';
$shippdetails = '' . ucfirst($details['customer']['name']) . '' . '
' . $details['customer']['shipping_phone'] . '
' . '' . $details['customer']['shipping_address'] . '
' . '' . $details['customer']['shipping_city'] . $details['customer']['shipping_state'] . '
' . '' . $details['customer']['shipping_country'] . '
' . '' . $details['customer']['shipping_zip'] . '
';
} else {
$customerdetails = '' . __('Walk-in Customer') . '';
$warehousedetails = '' . ucfirst($details['warehouse']['name']) . '';
$shippdetails = '-';
}
$settings['company_telephone'] = $settings['company_telephone'] != '' ? ", " . $settings['company_telephone'] : '';
$settings['company_state'] = $settings['company_state'] != '' ? ", " . $settings['company_state'] : '';
$userdetails = '' . ucfirst($details['user']['name']) . ' ' . '
' . $settings['company_name'] . $settings['company_telephone'] . '
' . '' . $settings['company_address'] . '
' . '' . $settings['company_city'] . $settings['company_state'] . '
' . '' . $settings['company_country'] . '
' . '' . $settings['company_zipcode'] . '
';
$details['customer']['details'] = $customerdetails;
$details['warehouse']['details'] = $warehousedetails;
//
$details['customer']['shippdetails'] = $shippdetails;
$details['user']['details'] = $userdetails;
$mainsubtotal = 0;
$sales = [];
foreach ($sess as $key => $value) {
$subtotal = $value['price'] * $value['quantity'];
$tax = ($subtotal * $value['tax']) / 100;
$sales['data'][$key]['name'] = $value['name'];
$sales['data'][$key]['quantity'] = $value['quantity'];
$sales['data'][$key]['price'] = Auth::user()->priceFormat($value['price']);
$sales['data'][$key]['tax'] = $value['tax'] . '%';
$sales['data'][$key]['product_tax'] = $value['product_tax'];
$sales['data'][$key]['tax_amount'] = Auth::user()->priceFormat($tax);
$sales['data'][$key]['subtotal'] = Auth::user()->priceFormat($value['subtotal']);
$mainsubtotal += $value['subtotal'];
}
$discount = !empty($request->discount) ? $request->discount : 0;
$sales['discount'] = Auth::user()->priceFormat($discount);
$total = $mainsubtotal - $discount;
$sales['sub_total'] = Auth::user()->priceFormat($mainsubtotal);
$sales['total'] = Auth::user()->priceFormat($total);
//for barcode
$productServices = ProductService::where('created_by', '=', \Auth::user()->creatorId())->get();
$barcode = [
'barcodeType' => Auth::user()->barcodeType(),
'barcodeFormat' => Auth::user()->barcodeFormat(),
];
return view('quotation.printview', compact('details', 'sales', 'customer', 'productServices', 'barcode'));
}
public function quotation($quotation_Id)
{
$settings = Utility::settings();
$quotationId = Crypt::decrypt($quotation_Id);
$quotation = Quotation::where('id', $quotationId)->first();
$data = \DB::table('settings');
$data = $data->where('created_by', '=', $quotation->created_by);
$data1 = $data->get();
foreach ($data1 as $row) {
$settings[$row->name] = $row->value;
}
$customer = $quotation->customer;
$totalTaxPrice = 0;
$totalQuantity = 0;
$totalRate = 0;
$totalDiscount = 0;
$taxesData = [];
$items = [];
foreach ($quotation->items as $product) {
$item = new \stdClass();
$item->name = !empty($product->product()) ? $product->product()->name : '';
$item->quantity = $product->quantity;
$item->tax = $product->tax;
$item->discount = $product->discount;
$item->price = $product->price;
$item->description = $product->description;
$totalQuantity += $item->quantity;
$totalRate += $item->price;
$totalDiscount += $item->discount;
$taxes = Utility::tax($product->tax);
$itemTaxes = [];
if (!empty($item->tax)) {
foreach ($taxes as $tax) {
$taxPrice = Utility::taxRate($tax->rate, $item->price, $item->quantity);
$totalTaxPrice += $taxPrice;
$itemTax['name'] = $tax->name;
$itemTax['rate'] = $tax->rate . '%';
$itemTax['price'] = Utility::priceFormat($settings, $taxPrice);
$itemTaxes[] = $itemTax;
if (array_key_exists($tax->name, $taxesData)) {
$taxesData[$tax->name] = $taxesData[$tax->name] + $taxPrice;
} else {
$taxesData[$tax->name] = $taxPrice;
}
}
$item->itemTax = $itemTaxes;
} else {
$item->itemTax = [];
}
$items[] = $item;
}
$quotation->itemData = $items;
$quotation->totalTaxPrice = $totalTaxPrice;
$quotation->totalQuantity = $totalQuantity;
$quotation->totalRate = $totalRate;
$quotation->totalDiscount = $totalDiscount;
$quotation->taxesData = $taxesData;
$logo = asset(Storage::url('uploads/logo/'));
$company_logo = Utility::getValByName('company_logo_dark');
$quotation_logo = Utility::getValByName('quotation_logo');
if (isset($quotation_logo) && !empty($quotation_logo)) {
$img = Utility::get_file('quotation_logo/') . $quotation_logo;
} else {
$img = asset($logo . '/' . (isset($company_logo) && !empty($company_logo) ? $company_logo : 'logo-dark.png'));
}
if ($quotation) {
$color = '#' . $settings['quotation_color'];
$font_color = Utility::getFontColor($color);
return view('quotation.templates.' . $settings['quotation_template'], compact('quotation', 'color', 'settings', 'customer', 'img', 'font_color'));
} else {
return redirect()->back()->with('error', __('Permission denied.'));
}
}
}