Файловый менеджер - Редактировать - /home/clickysoft/public_html/jmapi5.clickysoft.net/Models.tar
Назад
ProductsImport.php 0000644 00000002127 15021222520 0010244 0 ustar 00 <?php namespace App\Models; use App\Http\Controllers\Traits\MediaUploadingTrait; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; class ProductsImport extends Model implements HasMedia { use HasFactory, InteractsWithMedia, MediaUploadingTrait; protected $dates = [ 'created_at', 'updated_at', 'deleted_at', ]; protected $casts = [ 'created_at' => 'date:m-d-Y', 'updated_at' => 'date:m-d-Y', ]; protected $fillable = [ 'imported_by_id', 'status', 'completed_at', 'created_at', 'updated_at', ]; public function user(): BelongsTo { return $this->belongsTo(User::class, 'imported_by_id'); } public function getFileUrlAttribute() { $file = $this->getMedia('file_import')->last(); if ($file) { $file->url = $file->getUrl(); } return $file; } } OrderNotes.php 0000644 00000001512 15021222520 0007327 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; class OrderNotes extends Model implements HasMedia { use HasFactory, InteractsWithMedia; protected $dates = [ 'created_at', 'updated_at', 'deleted_at', ]; protected $casts = [ 'created_at' => 'date:m-d-Y', 'updated_at' => 'date:m-d-Y', ]; protected $fillable = [ 'user_id', 'order_id', 'note', 'created_at', 'updated_at', ]; public function user() { return $this->belongsTo(User::class, 'user_id'); } public function order() { return $this->belongsTo(Order::class, 'order_id'); } } AddressBook.php 0000644 00000002273 15021222520 0007450 0 ustar 00 <?php namespace App\Models; use \DateTimeInterface; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class AddressBook extends Model { use HasFactory; public $table = 'address_books'; protected $dates = [ 'created_at', 'updated_at', 'deleted_at', ]; protected $casts = [ 'created_at' => 'date:m-d-Y', 'updated_at' => 'date:m-d-Y', ]; protected $fillable = [ 'user_id', 'company_name', 'primary_contact_name', 'primary_contact_email', 'secondary_contact_name', 'secondary_contact_email', 'address_line_1', 'address_line_2', 'city', 'state_id', 'zipcode', 'phone_number', 'is_default', 'created_at', 'updated_at', 'deleted_at', ]; public function user() { return $this->belongsTo(User::class, 'user_id'); } protected function serializeDate(DateTimeInterface $date) { return $date->format('Y-m-d H:i:s'); } public function state() { return $this->belongsTo(StateSalesTax::class, 'state_id'); } } OrderItemCustomizationSvg.php 0000644 00000001356 15021222520 0012414 0 ustar 00 <?php namespace App\Models; use App\Http\Controllers\Traits\MediaUploadingTrait; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; class OrderItemCustomizationSvg extends Model implements HasMedia { use HasFactory, InteractsWithMedia, MediaUploadingTrait; protected $fillable = [ 'order_id', 'order_item_id', 'customization_index', 'file_content', 'file_name', ]; protected $appends = [ 'customization_svg_url', ]; public function getCustomizationSvgUrlAttribute() { return asset('/storage/customization_svg/'.$this->file_name); } } ContactQuery.php 0000644 00000001635 15021222520 0007672 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; class ContactQuery extends Model { use HasFactory; protected $fillable = [ 'name', 'email', 'phone', 'subject', 'message', 'location_id', 'department', 'is_read', 'create_at', 'updated_at', ]; protected $dates = [ 'created_at', 'updated_at', ]; protected $casts = [ 'created_at' => 'date:m-d-Y', 'updated_at' => 'date:m-d-Y', ]; public const DEPARTMENTS = [ 'Sales Team', 'Order Help Desk', 'Graphics and Artwork', 'Accounting', ]; public function location(): BelongsTo { return $this->belongsTo(StoreLocation::class, 'location_id'); } } OurPartner.php 0000644 00000003124 15021222520 0007345 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; use Spatie\MediaLibrary\MediaCollections\Models\Media; class OurPartner extends Model implements HasMedia { use HasFactory, InteractsWithMedia; public const STATUS_RADIO = [ '1' => 'Enable', '0' => 'Disable', ]; protected $appends = [ 'logo', ]; protected $hidden = [ 'remember_token', 'password', ]; protected $dates = [ 'created_at', 'updated_at', ]; protected $casts = [ 'created_at' => 'date:m-d-Y', 'updated_at' => 'date:m-d-Y', ]; protected $fillable = [ 'title', 'status', 'created_at', 'updated_at', ]; public function registerMediaConversions(Media $media = null): void { $this->addMediaConversion('thumb')->fit('crop', 50, 50); $this->addMediaConversion('preview')->fit('crop', 120, 120); } public function getStatusNameAttribute() { return self::STATUS_RADIO[$this->status]; } public function getLogoAttribute() { $file = $this->getMedia('logo')->last(); if ($file) { $file->url = $file->getUrl(); $file->thumbnail = $file->getUrl('thumb'); $file->preview = $file->getUrl('preview'); } return $file; } public function scopeActive($query) { return $query->where('status', 1); } } OrderItemVariation.php 0000644 00000000512 15021222520 0011011 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class OrderItemVariation extends Model { use HasFactory; protected $guarded = []; public function variation() { return $this->belongsTo(Variation::class, 'variation_id'); } } Role.php 0000644 00000001637 15021222520 0006154 0 ustar 00 <?php namespace App\Models; use App\Models\Scopes\UserOrganization; use DateTimeInterface; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Role extends Model { use HasFactory; public $table = 'roles'; protected $dates = [ 'created_at', 'updated_at', ]; protected $fillable = [ 'organization_id', 'title', 'created_at', 'updated_at', ]; protected static function booted(): void { static::addGlobalScope(new UserOrganization()); } protected function serializeDate(DateTimeInterface $date) { return $date->format('Y-m-d H:i:s'); } public function organization() { return $this->belongsTo(Organization::class, 'organization_id'); } public function permissions() { return $this->belongsToMany(Permission::class); } } StateSalesTax.php 0000644 00000001136 15021222520 0007772 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class StateSalesTax extends Model { use HasFactory; protected $table = 'state_sales_taxes'; protected $fillable = [ 'name', 'tax_percentage', ]; protected $dates = [ 'created_at', 'updated_at', ]; protected $casts = [ 'created_at' => 'date:m-d-Y', 'updated_at' => 'date:m-d-Y', ]; protected function getTaxPercentageAttribute($value): float { return (float) trim($value); } } ReportSales.php 0000644 00000002620 15021222520 0007507 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class ReportSales extends Model { use HasFactory; protected $table = 'report_sales'; public const REPORTS_MODE = [ 'previous_month' => 'previousMonth', 'current_month' => 'currentMonth', 'previous_year' => 'previousYear', 'current_year' => 'currentYear', 'all' => 'untilToday', ]; public function scopePreviousMonth($query) { $start_date = now()->startOfMonth()->subMonth(); $end_date = now()->endOfMonth()->subMonth(); $query->whereBetween('date', [$start_date, $end_date]); } public function scopeCurrentMonth($query) { $start_date = now()->startOfMonth(); $end_date = now()->endOfMonth(); $query->whereBetween('date', [$start_date, $end_date]); } public function scopePreviousYear($query) { $start_date = now()->startOfYear()->subYear(); $end_date = now()->endOfYear()->subYear(); $query->whereBetween('date', [$start_date, $end_date]); } public function scopeCurrentYear($query) { $start_date = now()->startOfYear(); $end_date = now()->endOfYear(); $query->whereBetween('date', [$start_date, $end_date]); } public function scopeUntilToday($query) { return $query; } } CartItem.php 0000644 00000001320 15021222520 0006750 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class CartItem extends Model { use HasFactory; protected $fillable = [ 'cart_id', 'attribute_id', 'attribute_option_id', ]; protected $dates = [ 'created_at', 'updated_at', ]; protected $casts = [ 'created_at' => 'date:m-d-Y', 'updated_at' => 'date:m-d-Y', ]; public function attribute() { return $this->belongsTo(Attribute::class, 'attribute_id'); } public function attributeOption() { return $this->belongsTo(AttributeOption::class, 'attribute_option_id'); } } Order.php 0000644 00000104234 15021222520 0006323 0 ustar 00 <?php namespace App\Models; use App\Http\Controllers\Traits\MediaUploadingTrait; use App\Http\Resources\Admin\OrderInfoResource; use App\Notifications\OrderApprovedConfirmedNotification; use App\Notifications\OrderArtworkReminderNotification; use App\Notifications\OrderCompletedNotification; use App\Notifications\OrderPickedShippedNotification; use Barryvdh\DomPDF\Facade\Pdf; use \DateTimeInterface; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Http\Request; use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Storage; class Order extends Model { use HasFactory, MediaUploadingTrait; protected $guarded = ['_token']; public const PAYMENT_STATUS_RADIO = [ 'Unpaid' => 'Unpaid', 'Paid' => 'Paid', ]; public const PAYMENT_MODE_RADIO = [ 'Partial', 'Full', ]; public const PAYMENT_TYPE_RADIO = [ 'Cash' => 'Cash', 'Credit Card' => 'Credit Card', 'Purchase Order' => 'Purchase Order', 'Check' => 'Check', 'PayJunction Invoice' => 'PayJunction Invoice', 'None' => 'None', ]; public const ORDER_TYPE_RADIO = [ 'Order' => 'Order', 'Quote' => 'Quote', ]; public const RUSH_ORDER_RADIO = [ 'Same Day' => 'Same Day', 'Rush Order 48' => 'Rush Order 48', 'Rush Order 72' => 'Rush Order 72', ]; public const ADMIN_APPROVED = [ 'No', 'Yes', ]; public const WAIVE_OFF_OPTIONS = [ "Federal Government", "Reseller Exemption", "Out of tax nexus", "Non-Profit Organization", ]; public const DELIVERY_TYPE = [ 'Shipping' => 'Shipping', 'Pickup' => 'Pickup', ]; public const DELIVERY_PACKAGES = [ 'ups_next_day_air' => 'Overnight (1 Day)', 'ups_second_day_air' => '2nd Day Air (2 Days)', 'ups_three_day_select' => 'Priority Shipping', 'ups_ground' => 'Ground Shipping (5-7 days)', ]; public const REPORTS_MODE = [ 'previous_month' => 'previousMonth', 'current_month' => 'currentMonth', 'previous_year' => 'previousYear', 'current_year' => 'currentYear', 'all' => 'untilToday', ]; public $table = 'orders'; protected $dates = [ 'created_at', 'updated_at', 'deleted_at', ]; protected $casts = [ 'payment_date' => 'datetime', 'delivery_date' => 'date', 'event_date' => 'date', 'date_scheduled' => 'date', 'date_pick_or_ship_by' => 'date', ]; public const ADMIN_ORDER_STATUS_ALLOWED = [ 1 => [2 => "Order Acknowledgement", 10 => "Order Cancelled"], 2 => [ 3 => "Product Ordered/In Stock", 4 => "Artwork Received", 6 => "Proof sent to customer", 8 => "Waiting on customer", 9 => "Proof sign off received", 10 => "Order Cancelled", ], 3 => [ 5 => "Products Received/Shelved", 10 => "Order Cancelled", ], 4 => [10 => "Order Cancelled", 11 => "In Production"], 5 => [ 10 => "Order Cancelled", 11 => "In Production", ], 6 => [8 => "Waiting on customer", 9 => "Proof sign off received",], 7 => [10 => "Order Cancelled", 11 => "In Production"], 8 => [9 => "Proof sign off received",], 9 => [ 10 => "Order Cancelled", 11 => "In Production", ], 10 => [], 11 => [12 => "In Assembly/Cleaning"], 12 => [13 => "Complete/Customer Notified"] ]; protected function getPurchaseOrderCopyUrlAttribute() { return $this->purchase_order_copy ? asset('storage/order/' . $this->purchase_order_copy) : $this->purchase_order_copy; } public function user() { return $this->belongsTo(User::class, 'user_id'); } public function current_status() { return $this->belongsTo(Status::class, 'current_status_id'); } public function assigned_to() { return $this->belongsTo(User::class, 'assigned_to_id'); } public function shipping_address() { return $this->belongsTo(AddressBook::class, 'shipping_address_id'); } public function billing_address() { return $this->belongsTo(AddressBook::class, 'billing_address_id'); } protected function serializeDate(DateTimeInterface $date) { return $date->format('Y-m-d H:i:s'); } protected function getAdminApprovedStatusAttribute() { return self::ADMIN_APPROVED[$this->admin_approved]; } protected function getFormatedPaymentDateAttribute() { return $this->payment_date == null ? null : $this->payment_date->format('m-d-Y h:i:s'); } public function statuses() { return $this->belongsToMany(Status::class, 'order_status')->withPivot('notes', 'created_at', 'updated_at', 'user_id'); } public function items() { return $this->hasMany(OrderItems::class, 'order_id'); } public function itemVariations() { return $this->hasMany(OrderItemVariation::class, 'order_id'); } public function purchaseOrder() { return $this->belongsTo(PurchaseOrderToCreate::class, 'order_id'); } public function notes() { return $this->hasMany(OrderNotes::class, 'order_id'); } public function pickLocation() { return $this->belongsTo(StoreLocation::class, 'pickup_location_id'); } public function getOrderAddress($address_id, $prefix) { $address = AddressBook::find($address_id); if (!$address) return []; return [ $prefix . '_company_name' => $address->company_name, $prefix . '_primary_contact_name' => $address->primary_contact_name, $prefix . '_primary_contact_email' => $address->primary_contact_email, $prefix . '_secondary_contact_name' => $address->secondary_contact_name, $prefix . '_secondary_contact_email' => $address->secondary_contact_email, $prefix . '_address_line_1' => $address->address_line_1, $prefix . '_address_line_2' => $address->address_line_2, $prefix . '_city' => $address->city, $prefix . '_state' => $address->state?->name, $prefix . '_zipcode' => $address->zipcode, $prefix . '_phone_number' => $address->phone_number, ]; } public function str_random($number) { return str_pad($number, 3, 0, STR_PAD_LEFT); } public function str_random2() { $order = Order::orderBy('id', 'desc')->first(); if (!$order) return 1000; return ($order->id) + 1000; } public function storeOrderProducts($products, $user_id, $is_add_request = false): array { $variation_ids = $item_ids = $return_data = []; foreach ($products as $product) { $existing_order_item_clone = null; $price = ProductPrice::where(['id' => $product['price_id'], 'product_id' => $product['product_id']])->first(); //Get the new or existing pricing order item if (isset($product['item_id']) && $product['item_id'] != null) { $existing_order_item = OrderItems::find($product['item_id']); $accountable_price = $existing_order_item->price; $accountable_engraving_fee = $existing_order_item->engraving_fee; } else { $db_product = Product::find($product['product_id']); $price_range = ProductVariationRange::where('product_price_id', $price->id) ->where('qty_from', '<=', $product['quantity']) ->where('qty_to', '>=', $product['quantity']) ->first(); $accountable_price = $price_range->price; $accountable_engraving_fee = $db_product->engraving_fee; } $prodData = [ 'product_id' => $product['product_id'], 'price_id' => $product['price_id'], 'notes' => $product['notes'] ?? '', 'sketch_file' => $product['sketch_file'] ?? null, 'customization' => $product['product_customization'] ?? '[]', ]; if (isset($product['item_id']) && $product['item_id'] != null) { //Add another entry with difference if quantity has increased. if ($product['quantity'] > $existing_order_item->quantity) { $existing_order_item_clone = $existing_order_item->replicate(); $existing_order_item_clone->quantity = $product['quantity'] - $existing_order_item->quantity; $existing_order_item_clone->engraving_fee_total = $existing_order_item_clone->quantity * $existing_order_item_clone->engraving_fee; $existing_order_item_clone->total_price = ($existing_order_item_clone->quantity * $existing_order_item_clone->price) + $existing_order_item_clone->engraving_fee_total; $existing_order_item_clone->po_created = false; $existing_order_item_clone->created_at = new \DateTime(); $existing_order_item_clone->updated_at = new \DateTime(); $existing_order_item_clone->save(); $item_ids[] = $existing_order_item_clone->id; } else { $existing_order_item->update( array_merge($prodData, [ 'quantity' => $product['quantity'], 'total_price' => $accountable_price * $product['quantity'], ]) ); $existing_order_item->save(); } } else { $existing_order_item = OrderItems::create( array_merge($prodData, [ 'quantity' => $product['quantity'], 'order_id' => $this->id, 'total_price' => $accountable_price * $product['quantity'], 'qty_from' => $price_range->qty_from, 'qty_to' => $price_range->qty_to, 'price' => $accountable_price, ]) ); } if (isset($product['approve_consent'])) { $existing_order_item->approve_consent = $product['approve_consent']; } $template = ""; if (isset($product['template'])) { $template = $this->storePDF($product['template'], $user_id, 'order'); } //Check for Artwork Received Status if (isset($product['template']) || isset($product['product_customization'])) { if (!isset($return_data['artwork_check'])) { $return_data['artwork_check'] = 1; } $existing_order_item->engraving_fee = $accountable_engraving_fee; $existing_order_item->engraving_fee_total = $accountable_engraving_fee * $existing_order_item->quantity; $existing_order_item->total_price_after_engraving = $existing_order_item->total_price + $existing_order_item->engraving_fee_total; } else { $existing_order_item->total_price_after_engraving = $existing_order_item->total_price + $existing_order_item->engraving_fee_total; } $existing_order_item->save(); if ($template != "") { $existing_order_item->template = $template ?? $existing_order_item->template; //Create PNG from pdf template pdfToImages($user_id, $existing_order_item->id, $existing_order_item->template); } $existing_order_item->image = $image ?? $existing_order_item->image; $existing_order_item->product_name = $existing_order_item->product?->name; $existing_order_item->save(); $item_ids[] = $existing_order_item->id; //Store Order Item Combination foreach ($price->combinations ?? [] as $com) { $v = OrderItemVariation::updateOrCreate([ 'order_id' => $this->id, 'product_id' => $product['product_id'], 'order_item_id' => $existing_order_item->id, 'variation_id' => $com->variation_id, ], [ 'order_id' => $this->id, 'product_id' => $product['product_id'], 'order_item_id' => $existing_order_item->id, 'variation_id' => $com->variation_id, ]); if ($existing_order_item_clone) { $v_clone = $v->replicate(); $v_clone->order_item_id = $existing_order_item_clone->id; $v_clone->save(); $variation_ids[] = $v_clone->id; } $variation_ids[] = $v->id; } } if (!$is_add_request) { $this->itemVariations()->whereNotIn('id', $variation_ids)->delete(); $this->items()->whereNotIn('id', $item_ids)->delete(); } $this->save(); return $return_data; } public function createPurchaseOrderItem() { $items_not_to_delete = []; foreach ($this->items as $item) { if (!$item->po_created) { $po_to_create_item = PurchaseOrderToCreate::updateOrCreate( [ 'order_item_id' => $item->id, ], [ 'order_id' => $this->id, 'order_item_id' => $item->id, 'product_id' => $item->product_id, 'price_id' => $item->price_id, 'quantity' => $item->quantity, ] ); $items_not_to_delete[] = $po_to_create_item->id; } } PurchaseOrderToCreate::where('order_id', $this->id)->whereNotIn('id', $items_not_to_delete)->delete(); } public function deletePurchaseOrderItem() { PurchaseOrderToCreate::where('order_id', $this->id)->delete(); } public function stockLocation(): BelongsTo { return $this->belongsTo(StockLocation::class, 'stock_location_id'); } public function invoice(): BelongsTo { return $this->belongsTo(OrderInvoice::class, 'invoice_id'); } public function payment(): BelongsTo { return $this->belongsTo(PayJunctionPayments::class, 'payment_id'); } public function createInvoice() { $payment_url = $pj_invoice_url = null; if ($this->payment_status == "Unpaid") { $payment_url = config('app.react_app_payment_url') . $this->id; $pj_invoice_url = generatePJInvoice($this); } //Business Information $site_email = SiteSetting::where('key', 'Site Email')->first(); $site_phone = SiteSetting::where('key', 'Site Phone')->first(); $location_1 = SiteSetting::where('key', 'Location')->first(); $location_2 = SiteSetting::where('key', 'Location 2')->first(); $user_id = $this->user_id; $pdf = PDF::loadView('partials.invoice', [ 'payment_url' => $payment_url, 'pj_invoice_url' => $pj_invoice_url->hostedInvoiceUrl ?? null, 'invoice_number' => $this->order_number, 'invoice_date' => now(), 'order' => new OrderInfoResource($this), 'customer' => $this->user, 'orderDetails' => $this->items, 'site_email' => $site_email->value ?? "NA", 'site_phone' => $site_phone->value ?? "NA", 'location_1' => $location_1->value ?? "NA", 'location_2' => $location_2->value ?? "NA", ])->setPaper('A4')->setOption([ 'fontDir' => public_path(), ]); $pdf_name = $this->order_number . '.pdf'; $file_path = public_path('storage/order/' . $user_id . '/' . $pdf_name); if (!Storage::disk('order')->exists($user_id)) { Storage::disk('order')->makeDirectory($user_id); } $pdf->save($file_path); $invoice = OrderInvoice::updateOrCreate([ 'invoice_number' => $this->order_number, ], [ 'order_id' => $this->id, 'invoice_number' => $this->order_number, 'pdf' => $this->user_id . '/' . $this->order_number . '.pdf', ]); $this->invoice_id = $invoice->id; $this->save(); return $invoice; } public function getAllowedStatus() { return isset(Order::ADMIN_ORDER_STATUS_ALLOWED[$this->current_status_id]) ? Order::ADMIN_ORDER_STATUS_ALLOWED[$this->current_status_id] : []; } public function getOrderTotals(Request $request, $order = null): array { //Calculate Product totals $data = $discount = []; $product_total = $shipping_amount = $engraving_fee = $rush_order_fee = $order_total = 0; $engraving_fee_of_all_products = 0; foreach ($request->products as $product) { $p_engraving = 0; if (isset($product['item_id']) && $product['item_id'] != null) { $existing_order_item = OrderItems::find($product['item_id']); $accountable_price = $existing_order_item->price; $accountable_engraving_fee = $existing_order_item->engraving_fee; } else { $db_product = Product::find($product['product_id']); $db_product_price = ProductPrice::find($product['price_id']); $price_range = ProductVariationRange::where('product_price_id', $db_product_price->id) ->where('qty_from', '<=', $product['quantity']) ->where('qty_to', '>=', $product['quantity']) ->first(); $accountable_price = $price_range->price; $accountable_engraving_fee = $db_product->engraving_fee; } $product_total += $accountable_price * $product['quantity']; $p_total = $accountable_price * $product['quantity']; if (isset($product['template']) || isset($product['customization']) || isset($product['product_customization'])) { $engraving_fee += $accountable_engraving_fee * $product['quantity']; $p_engraving = $accountable_engraving_fee * $product['quantity']; } else if (isset($product['include_engraving_fee']) && $product['include_engraving_fee']) { $engraving_fee += $accountable_engraving_fee * $product['quantity']; $p_engraving = $accountable_engraving_fee * $product['quantity']; } $data['products'][] = [ 'product_id' => $product['product_id'], 'price_id' => $product['price_id'], 'engraving_fee' => $p_engraving, 'total' => $p_total, 'total_with_engraving' => $p_total + $p_engraving, ]; } $product_total += $engraving_fee; $engraving_fee_of_all_products += $engraving_fee; $data['items_total'] = $product_total; if ($request['delivery_type'] == 'Shipping') { if ($request->has("third_party_shipping")) { $shipping_amount = (float)$request->get("shipping_total_amount"); } else { $customer_id = config('app.web_ship_customer_id'); $base_url = config('app.web_ship_base_url'); $endpoint = "{$base_url}/customers/{$customer_id}/quote"; $request_body = prepareDataForShippingQuote($request); $response = getShippingQuoteServices($request_body, $endpoint); if ($response['data']) { $shipping_amount = $response['data']['totalAmount']; } } } $billingAddress = AddressBook::find($request['billing_address_id']); $state = StateSalesTax::find($billingAddress->state_id); $state_sales_tax = $state->tax_percentage ?? 0; $data['rush_order'] = [ 'type' => null, 'percentage' => 0.00, ]; if ($request->rush_order) { $rush_order_fee = SiteSetting::where('key', $request->rush_order)->first(); if (!empty($rush_order_fee)) { $rush_order_fee = $rush_order_fee->value; $data['rush_order'] = [ 'type' => $request->rush_order, 'percentage' => $rush_order_fee, ]; } } $order_total += $product_total; //Rush Order $rush_order_amount = $order_total * ($rush_order_fee ?? 0) / 100; $order_total += $rush_order_amount; //Calculate coupon discount if ($request->has('coupon_code')) { $coupon = Coupon::where('code', $request['coupon_code'])->first(); if ($order && $order->coupon_id == $coupon->id) { $discount = [ 'coupon' => $coupon, 'coupon_id' => $order->coupon_id, 'discount_type' => $order->discount_type, 'discount_value' => $order->discount_value, ]; if ($order->discount_type == 'fixed') { $discount['order_discount'] = $order->discount_value; } else { $discount['order_discount'] = $order_total * ($order->discount_value ?? 0) / 100; } } else { $discount = [ 'coupon' => $coupon, 'coupon_id' => $coupon->id, 'discount_type' => $coupon->discount_type, 'discount_value' => $coupon->discount_value, ]; if ($coupon->discount_type == 'fixed') { $discount['order_discount'] = $coupon->discount_value; } else { $discount['order_discount'] = $order_total * ($coupon->discount_value ?? 0) / 100; } } $order_total -= $discount['order_discount']; } $state_tax = $order_total * ($state_sales_tax ?? 0) / 100; $order_total += $shipping_amount; //Add sales tax in total if not waved off $order_total += $request->waive_off_sales_tax == 1 ? 0 : $state_tax; $data['rush_order']['amount'] = $rush_order_amount; $data['sales_tax'] = [ 'state' => $state->name, 'percentage' => $state_sales_tax, 'amount' => $state_tax, ]; $data['discount'] = $discount; $data['engraving_fee_of_all_products'] = $engraving_fee_of_all_products; $data['shipping_charges'] = $shipping_amount; $data['grand_total'] = $order_total; return $data; } public function sendOrderStatusUpdatedMail($notes = null): void { $company_phone_1 = SiteSetting::where('key', 'Site Phone')->first(); $company_phone_2 = SiteSetting::where('key', 'Site Phone 2')->first(); $data = [ 'order_number' => $this->order_number, 'tracking_number' => $this->tracking_number, 'customer_name' => $this->user->name ?? '', 'notes' => $notes, 'company_phone_1' => $company_phone_1->value ?? "N/A", 'company_phone_2' => $company_phone_2->value ?? "N/A", 'invoice_path' => $this->invoice->invoicePath ?? '', ]; if ($this->tracking_number != null) { $data['tracking_number'] = "https://www.ups.com/track?track=yes&trackNums=" . $this->tracking_number; } if ($this->current_status->name == "Order Acknowledgement") { if ($this->payment_status == "Unpaid") { $pj_invoice = generatePJInvoice($this); if ($this->payment_status == "Unpaid") { $data['invoice_url'] = $pj_invoice->hostedInvoiceUrl ?? null; } } $this->user->notify(new OrderApprovedConfirmedNotification($data)); }/* else if ($this->current_status->name == "In Production") { $this->user->notify(new OrderInProductionNotification($data)); }else if ($this->current_status->name == "In Assembly/Cleaning") { //This email has been disabled by client $this->user->notify(new OrderInAssemblyCleaningNotification($data)); } else if ($this->current_status->name == "Waiting on customer") { $this->user->notify(new OrderWaitingOnCustomerNotification($data)); }*/ else if ($this->current_status->name == "Complete/Customer Notified") { //Adding additional data required in email template $data['delivery_type'] = $this->delivery_type; $data['billing_details'] = [ 'Primary Contact Name' => $this->billing_primary_contact_name, 'Primary Contact Email' => $this->billing_primary_contact_email, 'Address' => $this->billing_address_line_1, 'Other' => $this->billing_city . " " . $this->billing_state . " " . $this->billing_zipcode, ]; if ($this->delivery_type == "Shipping") { $data['delivery_details'] = [ 'Primary Contact Name' => $this->shipping_primary_contact_name, 'Primary Contact Email' => $this->shipping_primary_contact_email, 'Address' => $this->shipping_address_line_1, 'Other' => $this->shipping_city . " " . $this->shipping_state . " " . $this->shipping_zipcode, ]; if ($this->tracking_number != null && $this->tracking_number != 'undefined') { $data['tracking_number'] = "https://www.ups.com/track?track=yes&trackNums=" . $this->tracking_number; $data['tracking_number_digits'] = $this->tracking_number; } } else { $data['delivery_details'] = [ 'Pickup Location' => $this->pickLocation?->title, ]; } if ($this->payment_status == "Paid") { $data = $this->getPaymentInfoData($data); } else { $pj_invoice = generatePJInvoice($this); if ($this->payment_status == "Paid") { $data = $this->getPaymentInfoData($data); } else { $data['payment_details'] = [ 'Payment Status' => "Unpaid", 'Invoice URL' => $pj_invoice->hostedInvoiceUrl ?? null, ]; } } $this->user->notify(new OrderCompletedNotification($data)); } else if ($this->current_status->name == "Proof sent to customer") { $approve_url = config('app.react_app_artwork_approve_url'); $templates = $attachments = []; foreach ($this->items as $item) { if (!empty($item->template)) { $templates[] = '<li style="text-align: center; list-style: none"><strong><a href="' . asset('storage/order/' . $item->template) . '" style="text-decoration: underline; font-size: 25px; color: blue"><u>CLICK HERE TO VIEW ARTWORK</u></a></strong></li>'; $attachments[] = $item->templateUrl; } } $data = [ 'order_number' => $this->order_number, 'user' => $this->user, 'notes' => $this->notes, 'approve_url' => $approve_url . $this->id, 'templates' => $templates, 'company_phone_1' => $company_phone_1->value ?? "N/A", 'company_phone_2' => $company_phone_2->value ?? "N/A", 'attachments' => $attachments, ]; $this->user->notify(new OrderArtworkReminderNotification($data)); } else if ($this->current_status->name == "Picked/Shipped") { //Need email verbiage for this if ($this->delivery_type == "Shipping") { if ($this->tracking_number != null && $this->tracking_number != 'undefined') { $data['tracking_number'] = "https://www.ups.com/track?track=yes&trackNums=" . $this->tracking_number; $data['tracking_number_digits'] = $this->tracking_number; $data['picked_shipped'] = "Shipped"; $data['subject_title'] = "Order #{$this->order_number} Shipped - Exciting News"; } $this->user->notify(new OrderPickedShippedNotification($data)); } }/* else { $this->user->notify(new OrderStatusUpdatedNotification($data)); }*/ } public function updateOrderCalculation() { $items_total = 0; $shipping_amount = 0; $order_items = $this->items; if ($this->delivery_type == 'Shipping') { if ($this->career_code === "3ps") { $shipping_amount = (float)$this->shipping_total_amount; } else { $customer_id = config('app.web_ship_customer_id'); $base_url = config('app.web_ship_base_url'); $endpoint = "{$base_url}/customers/{$customer_id}/quote"; $data_array = [ 'shipping_address_id' => $this->shipping_address_id, 'career_code' => $this->career_code, 'service_code' => $this->service_code, 'package_type_code' => $this->package_type_code, 'is_residential' => true, //Need to store in order ]; foreach ($order_items as $order_item) { $data_array['products'][] = [ 'price_id' => $order_item->price_id, 'quantity' => $order_item->quantity, ]; } $request = new Request(); $request->merge($data_array); $request_body = prepareDataForShippingQuote($request); $response = getShippingQuoteServices($request_body, $endpoint); if ($response['data']) { $shipping_amount = $response['data']['totalAmount']; } } } foreach ($order_items as $order_item) { $items_total += $order_item->total_price_after_engraving; } $grand_total = $items_total; $rush_order_amount = $items_total * ($this->rush_order_fee ?? 0) / 100; $grand_total += $rush_order_amount; //Recalculate discount here if ($this->coupon_id != null) { if ($this->discount_type == 'fixed') { $discount = $this->discount_value; } else { $discount = $grand_total * ($this->discount_value ?? 0) / 100; } $this->discount_total = $discount; $grand_total -= $discount; } $state_tax = $grand_total * ($this->state_sales_tax ?? 0) / 100; $grand_total += $state_tax; $this->items_total = $items_total; $this->rush_order_amount = $rush_order_amount; $this->shipping_charges = $shipping_amount; $this->sales_tax_amount = $state_tax; $this->grand_total = $grand_total; $this->remaining_order_amount = $grand_total - $this->paid_order_amount; $this->save(); } public function scopePreviousMonth($query) { $start_date = now()->startOfMonth()->subMonth(); $end_date = now()->endOfMonth()->subMonth(); $query->whereBetween('created_at', [$start_date, $end_date]); } public function scopeCurrentMonth($query) { $start_date = now()->startOfMonth(); $end_date = now()->endOfMonth(); $query->whereBetween('created_at', [$start_date, $end_date]); } public function scopePreviousYear($query) { $start_date = now()->startOfYear()->subYear(); $end_date = now()->endOfYear()->subYear(); $query->whereBetween('created_at', [$start_date, $end_date]); } public function scopeCurrentYear($query) { $start_date = now()->startOfYear(); $end_date = now()->endOfYear(); $query->whereBetween('created_at', [$start_date, $end_date]); } public function scopeUntilToday($query) { return $query; } public function partialPayments() { return $this->hasMany(OrderPartialPayments::class, 'order_id'); } /** * @param $data * @return mixed */ public function getPaymentInfoData($data): mixed { $data['payment_details'] = [ "Payment Status" => "Paid", "Payment Type" => $this->payment_type, ]; if ($this->payment_type == "Purchase Order") { $data['payment_details']['Purchase Order Number'] = $this->purchase_order_number; $data['payment_details']['Purchase Order Copy'] = $this->purchase_order_copy_url ?? 'N/A'; } else if ($this->payment_type == "Check") { $data['payment_details']['Check Number'] = $this->cheque_number; } else if ($this->payment_type == "Credit Card") { $data['payment_details'] = $this->payment ? [ 'Card Type' => $this->payment->account_type, 'Last Four' => $this->payment->last_four, 'Payment Date' => $this->payment->created_at->format('Y-m-d'), ] : []; } return $data; } public function copyOrderNotes($order_id) { $order = Order::find($order_id); foreach ($order->notes as $note) { $note_clone = $note->replicate(); $note_clone->order_id = $this->id; $note_clone->save(); $media = $note->getMedia('*'); foreach ($media as $media_item) { // Copy the file to the new model's media collection $note_clone->addMedia($media_item->getPath()) ->preservingOriginal() ->toMediaCollection('note_attachments', 'order'); } } } } ReportJobsCompleted.php 0000644 00000002641 15021222520 0011175 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class ReportJobsCompleted extends Model { use HasFactory; protected $table = 'report_jobs_completed'; public const REPORTS_MODE = [ 'previous_month' => 'previousMonth', 'current_month' => 'currentMonth', 'previous_year' => 'previousYear', 'current_year' => 'currentYear', 'all' => 'untilToday', ]; public function scopePreviousMonth($query) { $start_date = now()->startOfMonth()->subMonth(); $end_date = now()->endOfMonth()->subMonth(); $query->whereBetween('date', [$start_date, $end_date]); } public function scopeCurrentMonth($query) { $start_date = now()->startOfMonth(); $end_date = now()->endOfMonth(); $query->whereBetween('date', [$start_date, $end_date]); } public function scopePreviousYear($query) { $start_date = now()->startOfYear()->subYear(); $end_date = now()->endOfYear()->subYear(); $query->whereBetween('date', [$start_date, $end_date]); } public function scopeCurrentYear($query) { $start_date = now()->startOfYear(); $end_date = now()->endOfYear(); $query->whereBetween('date', [$start_date, $end_date]); } public function scopeUntilToday($query) { return $query; } } ProductVariation.php 0000644 00000000470 15021222520 0010542 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class ProductVariation extends Model { use HasFactory; protected $guarded = []; public function variation() { return $this->belongsTo(Variation::class); } } ReportSalesComparison.php 0000644 00000001072 15021222520 0011542 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class ReportSalesComparison extends Model { use HasFactory; protected $table = 'report_sales_comparison'; public const REPORTS_MODE = [ 'previous_year' => 'previousYear', 'current_year' => 'currentYear', 'custom' => 'customRange', ]; public function scopeCustomRange($query, $date_range): void { $query->whereBetween('date', [$date_range['year_from'], $date_range['year_to']]); } } PayJunctionPayments.php 0000644 00000000427 15021222520 0011233 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class PayJunctionPayments extends Model { use HasFactory; protected $table = "payments"; protected $guarded = [ "_token", ]; } Coupon.php 0000644 00000001626 15021222520 0006514 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Coupon extends Model { public const DISCOUNT_TYPE = [ 'fixed' => 'Fixed', 'percentage' => 'Percentage', ]; protected $fillable = [ 'code', 'discount_type', 'discount_value', 'expiry_date', 'number_of_usage', 'redemption_count', 'status', ]; protected $dates = [ 'created_at', 'updated_at', 'expiry_date', ]; protected $casts = [ 'created_at' => 'date:m-d-Y', 'updated_at' => 'date:m-d-Y', 'expiry_date' => 'date:m-d-Y', ]; public const STATUS_RADIO = [ '1' => 'Enabled', '0' => 'Disabled', ]; protected function getStatusNameAttribute() { return self::STATUS_RADIO[$this->status]; } } Category.php 0000644 00000003110 15021222520 0007014 0 ustar 00 <?php namespace App\Models; use App\Models\Scopes\UserOrganization; use DateTimeInterface; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; use Spatie\MediaLibrary\MediaCollections\Models\Media; class Category extends Model implements HasMedia { use InteractsWithMedia, HasFactory; public $table = 'categories'; protected $appends = [ 'image', ]; protected $dates = [ 'created_at', 'updated_at', ]; protected $fillable = [ 'organization_id', 'name', 'description', 'created_at', 'updated_at', ]; protected static function booted(): void { static::addGlobalScope(new UserOrganization); } protected function serializeDate(DateTimeInterface $date) { return $date->format('Y-m-d H:i:s'); } public function registerMediaConversions(Media $media = null): void { $this->addMediaConversion('thumb')->fit('crop', 100, 100); $this->addMediaConversion('preview')->fit('crop', 200, 200); } public function organization() { return $this->belongsTo(Organization::class, 'organization_id'); } public function getImageAttribute() { $file = $this->getMedia('image')->last(); if ($file) { $file->url = $file->getUrl(); $file->thumbnail = $file->getUrl('thumb'); $file->preview = $file->getUrl('preview'); } return $file; } } OrderItems.php 0000644 00000004563 15021222520 0007331 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Storage; class OrderItems extends Model { use HasFactory; protected $table = 'order_items'; protected $guarded = ['_token']; public function order() { return $this->belongsTo(Order::class); } public function purchaseOrderItems() { return $this->hasMany(PurchaseOrderItem::class, 'order_item_id'); } protected function getTemplateMediaAttribute() { return $this->template ? asset('storage/order/' . $this->template) : ''; } protected function getTemplateUrlAttribute() { return $this->template ? public_path('storage/order/' . $this->template) : ''; } protected function getImageUrlAttribute() { return $this->image ? asset('storage/order/' . $this->image) : ''; } public function product() { return $this->belongsTo(Product::class, 'product_id'); } public function productPrice() { return $this->belongsTo(ProductPrice::class, 'price_id'); } public function itemVariations() { return $this->hasMany(OrderItemVariation::class, 'order_id'); } public function orderItemVariations() { return $this->hasMany(OrderItemVariation::class, 'order_item_id'); } public function orderItemCustomizations() { return $this->hasMany(OrderItemCustomizationData::class, 'order_item_id'); } public function customizationSvg() { return $this->hasMany(OrderItemCustomizationSvg::class, 'order_item_id', 'id'); } protected function getInvoicePathAttribute() { return $this->invoice_number ? public_path('storage/order/' . $this->pdf) : ''; } public static function boot() { parent::boot(); static::deleting(function ($order_item) { if ($order_item->attachment) { if (Storage::disk('order')->exists($order_item->template)) { Storage::disk('order')->delete($order_item->template); } } foreach ($order_item->itemVariations as $variation) { $variation->delete(); } }); } } OrderArtworkReminder.php 0000644 00000000720 15021222520 0011356 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; class OrderArtworkReminder extends Model { use HasFactory; public function order(): BelongsTo { return $this->belongsTo(Order::class, 'order_id'); } public function user(): BelongsTo { return $this->belongsTo(User::class, 'user_id'); } } Status.php 0000644 00000001472 15021222520 0006533 0 ustar 00 <?php namespace App\Models; use App\Models\Scopes\UserOrganization; use DateTimeInterface; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Status extends Model { use HasFactory; public $table = 'statuses'; protected $dates = [ 'created_at', 'updated_at', ]; protected $fillable = [ 'organization_id', 'name', 'created_at', 'updated_at', ]; protected static function booted(): void { static::addGlobalScope(new UserOrganization); } protected function serializeDate(DateTimeInterface $date) { return $date->format('Y-m-d H:i:s'); } public function organization() { return $this->belongsTo(Organization::class, 'organization_id'); } } OrderItemCustomizationData.php 0000644 00000000572 15021222520 0012525 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class OrderItemCustomizationData extends Model { use HasFactory; protected $fillable = ['order_item_id', 'customization']; public function getMediaUrlAttribute() { return asset("storage/order/{$this->customization}"); } } ReportYearOverYear.php 0000644 00000001054 15021222520 0011015 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class ReportYearOverYear extends Model { use HasFactory; protected $table = 'report_sales'; public const REPORTS_MODE = [ 'previous_year' => 'previousYear', 'current_year' => 'currentYear', 'custom' => 'customRange', ]; public function scopeCustomRange($query, $date_range): void { $query->whereBetween('date', [$date_range['year_from'], $date_range['year_to']]); } } ReportPaymentsCollection.php 0000644 00000003135 15021222520 0012256 0 ustar 00 <?php namespace App\Models; use Carbon\Carbon; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class ReportPaymentsCollection extends Model { use HasFactory; protected $table = 'report_payment_collection'; public const REPORTS_MODE = [ 'previous_month' => 'previousMonth', 'current_month' => 'currentMonth', 'previous_year' => 'previousYear', 'current_year' => 'currentYear', 'monthly' => 'monthly', ]; public function scopePreviousMonth($query) { $start_date = now()->startOfMonth()->subMonth(); $end_date = now()->endOfMonth()->subMonth(); $query->whereBetween('date', [$start_date, $end_date]); } public function scopeCurrentMonth($query) { $start_date = now()->startOfMonth(); $end_date = now()->endOfMonth(); $query->whereBetween('date', [$start_date, $end_date]); } public function scopePreviousYear($query) { $start_date = now()->startOfYear()->subYear(); $end_date = now()->endOfYear()->subYear(); $query->whereBetween('date', [$start_date, $end_date]); } public function scopeCurrentYear($query) { $start_date = now()->startOfYear(); $end_date = now()->endOfYear(); $query->whereBetween('date', [$start_date, $end_date]); } public function scopeMonthly($query, $date) { $start_date = Carbon::make($date)->startOfMonth(); $end_date = Carbon::make($date)->endOfMonth(); $query->whereBetween('date', [$start_date, $end_date]); } } PurchaseOrderItem.php 0000644 00000002143 15021222520 0010631 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class PurchaseOrderItem extends Model { use HasFactory; protected $fillable = [ 'id', 'order_id', 'order_item_id', 'product_id', 'attribute_id', 'attribute_option_id', 'created_at', 'updated_at', ]; protected $appends = [ 'quantity' ]; public function product() { return $this->belongsTo(Product::class, 'product_id'); } public function attribute() { return $this->belongsTo(Attribute::class, 'attribute_id'); } public function attributeOption() { return $this->belongsTo(AttributeOption::class, 'attribute_option_id'); } public function orderItem() { return $this->belongsTo(OrderItems::class, 'order_item_id'); } public function order() { return $this->belongsTo(Order::class, 'order_id'); } protected function getQuantityAttribute() { return $this->orderItem->quantity; } } PurchaseOrderToCreate.php 0000644 00000001404 15021222520 0011440 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\HasMany; class PurchaseOrderToCreate extends Model { use HasFactory; protected $table = 'purchase_order_to_create'; protected $fillable = [ 'order_id', 'order_item_id', 'product_id', 'price_id', 'quantity', 'created_at', 'updated_at', ]; public function order() { return $this->belongsTo(Order::class, 'order_id'); } public function orders(): HasMany { return $this->hasMany(PurchaseOrderToCreate::class, 'product_id', 'product_id') ->where('price_id', $this->price_id); } } ReportJobsCompletedDetailed.php 0000644 00000000725 15021222520 0012632 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class ReportJobsCompletedDetailed extends Model { use HasFactory; protected $table = 'report_sales'; public const REPORTS_MODE = [ 'previous_year' => 'previousYear', 'current_year' => 'currentYear', 'custom' => 'customRange', 'daily' => 'dailyReport', 'weekly' => 'weeklyReport', ]; } OrderInvoice.php 0000644 00000001322 15021222520 0007632 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; class OrderInvoice extends Model { use HasFactory; protected $guarded = ['_token']; public function order(): BelongsTo { return $this->belongsTo(Order::class, 'order_id'); } protected function getInvoiceUrlAttribute() { return $this->invoice_number ? asset('storage/order/'.$this->pdf) : ''; } protected function getInvoicePathAttribute() { return $this->invoice_number ? public_path('storage/order/'.$this->pdf) : ''; } } Review.php 0000644 00000001514 15021222520 0006506 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Review extends Model { use HasFactory; protected $fillable = [ 'user_id', 'product_id', 'order_id', 'rating', 'comment', 'created_at', 'updated_at', ]; protected $dates = [ 'created_at', 'updated_at', ]; protected $casts = [ 'created_at' => 'date:m-d-Y', 'updated_at' => 'date:m-d-Y', ]; public function user() { return $this->belongsTo(User::class, 'user_id'); } public function product() { return $this->belongsTo(Product::class, 'product_id'); } public function order() { return $this->belongsTo(Order::class, 'order_id'); } } SiteSetting.php 0000644 00000000740 15021222520 0007507 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class SiteSetting extends Model { use HasFactory; protected $fillable = [ 'key', 'value', 'created_at', 'updated_at', ]; protected $dates = [ 'created_at', 'updated_at', ]; protected $casts = [ 'created_at' => 'date:m-d-Y', 'updated_at' => 'date:m-d-Y', ]; } Wishlist.php 0000644 00000000743 15021222520 0007056 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Wishlist extends Model { use HasFactory; protected $fillable = [ 'product_id', 'user_id', 'created_at', 'updated_at', ]; protected $dates = [ 'created_at', 'updated_at', ]; public function product() { return $this->belongsTo(Product::class, 'product_id'); } } StockLocation.php 0000644 00000001524 15021222520 0010022 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use \DateTimeInterface; class StockLocation extends Model { use HasFactory; protected $guarded = ['_token']; public const STATUS_RADIO = [ '1' => 'Enable', '0' => 'Disable', ]; protected $dates = [ 'created_at', 'updated_at', ]; protected $casts = [ 'created_at' => 'date:m-d-Y', 'updated_at' => 'date:m-d-Y', ]; protected function serializeDate(DateTimeInterface $date) { return $date->format('Y-m-d H:i:s'); } protected function getStatusNameAttribute() { return self::STATUS_RADIO[$this->status]; } public function scopeActive($query) { return $query->where('status', 1); } } Variation.php 0000644 00000001352 15021222520 0007201 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Variation extends Model { use HasFactory; public const STATUS_RADIO = [ 'Enable', 'Disable', ]; protected $fillable = [ 'type', 'value', 'vendor_id', 'vendor_price', 'sku', 'status', 'created_at', 'updated_at', ]; protected $dates = [ 'created_at', 'updated_at', ]; protected $casts = [ 'created_at' => 'date:m-d-Y', 'updated_at' => 'date:m-d-Y', ]; public function vendor() { return $this->belongsTo(Vendor::class, 'vendor_id', 'id'); } } User.php 0000644 00000006350 15021222520 0006166 0 ustar 00 <?php namespace App\Models; use Carbon\Carbon; use DateTimeInterface; use Hash; use App\Models\Scopes\UserOrganization; use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; use Spatie\MediaLibrary\MediaCollections\Models\Media; use Laravel\Sanctum\HasApiTokens; class User extends Authenticatable implements HasMedia, MustVerifyEmail { use Notifiable, InteractsWithMedia, HasFactory, HasApiTokens; public $table = 'users'; protected $appends = [ 'avatar', ]; protected $hidden = [ 'remember_token', 'password', ]; protected $dates = [ 'email_verified_at', 'created_at', 'updated_at', ]; protected $fillable = [ 'organization_id', 'first_name', 'last_name', 'email', 'password', 'contact_number', 'status', 'email_verified_at', 'remember_token', 'created_at', 'updated_at', ]; protected static function booted(): void { static::addGlobalScope(new UserOrganization()); } protected function serializeDate(DateTimeInterface $date) { return $date->format('Y-m-d H:i:s'); } public function getIsAdminAttribute() { return $this->roles()->where('id', 1)->exists(); } public function registerMediaConversions(Media $media = null): void { $this->addMediaConversion('thumb')->fit('crop', 100, 100); $this->addMediaConversion('preview')->fit('crop', 200, 200); } public function organization() { return $this->belongsTo(Organization::class, 'organization_id'); } public function companies() { // return $this->belongsToMany(Company::class); return $this->belongsToMany(Company::class, 'company_user', 'user_id', 'company_id') ->withPivot('branch_id'); } public function setPasswordAttribute($input) { if ($input) { $this->attributes['password'] = app('hash')->needsRehash($input) ? Hash::make($input) : $input; } } public function getAvatarAttribute() { $file = $this->getMedia('avatar')->last(); if ($file) { $file->url = $file->getUrl(); $file->thumbnail = $file->getUrl('thumb'); $file->preview = $file->getUrl('preview'); } return $file; } public function getFullNameAttribute() { return $this->first_name . ' ' . $this->last_name; } public function getEmailVerifiedAtAttribute($value) { return $value ? Carbon::createFromFormat('Y-m-d H:i:s', $value)->format(config('panel.date_format') . ' ' . config('panel.time_format')) : null; } public function setEmailVerifiedAtAttribute($value) { $this->attributes['email_verified_at'] = $value ? Carbon::createFromFormat(config('panel.date_format') . ' ' . config('panel.time_format'), $value)->format('Y-m-d H:i:s') : null; } public function roles() { return $this->belongsToMany(Role::class); } } OrderPaymentReminder.php 0000644 00000000720 15021222520 0011342 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; class OrderPaymentReminder extends Model { use HasFactory; public function order(): BelongsTo { return $this->belongsTo(Order::class, 'order_id'); } public function user(): BelongsTo { return $this->belongsTo(User::class, 'user_id'); } } Cart.php 0000644 00000002525 15021222520 0006141 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Storage; class Cart extends Model { use HasFactory; protected $casts = [ 'created_at' => 'date:m-d-Y', 'updated_at' => 'date:m-d-Y', ]; protected $fillable = [ 'user_id', 'product_id', 'price_id', 'customization', 'attachment', 'quantity', 'created_at', 'updated_at', ]; public function product() { return $this->belongsTo(Product::class, 'product_id'); } protected function getAttachmentUrlAttribute() { return $this->attachment ? asset('storage/order/'.$this->attachment) : $this->attachment; } public function price() { return $this->belongsTo(ProductPrice::class, 'price_id'); } public function items() { return $this->hasMany(CartItem::class, 'cart_id'); } public static function boot() { parent::boot(); static::deleting(function($cart) { if ($cart->attachment){ if (Storage::disk('order')->exists($cart->attachment)){ Storage::disk('order')->delete($cart->attachment); } } }); } } Vendor.php 0000644 00000001154 15021222520 0006502 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Vendor extends Model { use HasFactory; protected $fillable = [ 'name', 'email', 'secondary_email', 'phone', 'address', 'account_number', 'payment_terms', 'credit_card_ending', 'created_at', 'updated_at', ]; protected $dates = [ 'created_at', 'updated_at', ]; protected $casts = [ 'created_at' => 'date:m-d-Y', 'updated_at' => 'date:m-d-Y', ]; } ProductVariationCombination.php 0000644 00000000524 15021222520 0012725 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class ProductVariationCombination extends Model { use HasFactory; protected $guarded = []; public function variation() { return $this->belongsTo(Variation::class, 'variation_id'); } } Permission.php 0000644 00000001026 15021222520 0007373 0 ustar 00 <?php namespace App\Models; use DateTimeInterface; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Permission extends Model { use HasFactory; public $table = 'permissions'; protected $dates = [ 'created_at', 'updated_at', ]; protected $fillable = [ 'title', 'created_at', 'updated_at', ]; protected function serializeDate(DateTimeInterface $date) { return $date->format('Y-m-d H:i:s'); } } PurchaseOrderDetails.php 0000644 00000002043 15021222520 0011317 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; class PurchaseOrderDetails extends Model { use HasFactory; protected $table = 'purchase_order_details'; protected $guarded = [ '_token', ]; public function product(): BelongsTo { return $this->belongsTo(Product::class, 'product_id', 'id'); } public function variation(): BelongsTo { return $this->belongsTo(Variation::class, 'product_id', 'id'); } public function productPrice(): BelongsTo { return $this->belongsTo(ProductPrice::class, 'price_id', 'id'); } public function officeSupply() { return $this->belongsTo(OfficeSupplies::class, 'product_id', 'id'); } public function ordersPODetails(): HasMany { return $this->hasMany(PurchaseOrderOrderDetails::class, 'purchase_order_details_id'); } } ReportSalesTax.php 0000644 00000003070 15021222520 0010164 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class ReportSalesTax extends Model { use HasFactory; protected $table = 'report_sales_tax'; public const REPORTS_MODE = [ 'previous_month' => 'previousMonth', 'current_month' => 'currentMonth', 'previous_year' => 'previousYear', 'current_year' => 'currentYear', 'all' => 'untilToday', ]; public function scopePreviousMonth($query) { $start_date = now()->startOfMonth()->subMonth(); $end_date = now()->endOfMonth()->subMonth(); $query->whereBetween('date', [$start_date, $end_date]); } public function scopeCurrentMonth($query) { $start_date = now()->startOfMonth(); $end_date = now()->endOfMonth(); $query->whereBetween('date', [$start_date, $end_date]); } public function scopePreviousYear($query) { $start_date = now()->startOfYear()->subYear(); $end_date = now()->endOfYear()->subYear(); $query->whereBetween('date', [$start_date, $end_date]); } public function scopeCurrentYear($query) { $start_date = now()->startOfYear(); $end_date = now()->endOfYear(); $query->whereBetween('date', [$start_date, $end_date]); } public function scopeUntilToday($query) { return $query; } public function scopeCustomRange($query, $date_range) { $query->whereBetween('date', [$date_range['year_from'], $date_range['year_to']]); } } StoreLocation.php 0000644 00000002020 15021222520 0010023 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; class StoreLocation extends Model { use HasFactory; protected $fillable = [ 'title', 'address', 'latitude', 'longitude', 'state_id', 'status', 'created_at', 'updated_at', ]; protected $dates = [ 'created_at', 'updated_at', ]; protected $casts = [ 'created_at' => 'date:m-d-Y', 'updated_at' => 'date:m-d-Y', ]; public const STATUS_RADIO = [ '1' => 'Enabled', '0' => 'Disabled', ]; public function state(): BelongsTo { return $this->belongsTo(StateSalesTax::class, 'state_id'); } public function scopeActive($query) { return $query->where('status', 1); } protected function getStatusNameAttribute() { return self::STATUS_RADIO[$this->status]; } } OrderPartialPayments.php 0000644 00000002625 15021222520 0011362 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; class OrderPartialPayments extends Model { use HasFactory; protected $fillable = [ 'order_id', 'charged_by_id', 'payment_id', 'payment_type', 'cheque_number', 'purchase_order_number', 'purchase_order_copy', 'amount', 'created_at', 'updated_at', ]; public const PAYMENT_TYPE_RADIO = [ 'Cash' => 'Cash', 'Credit Card' => 'Credit Card', 'Purchase Order' => 'Purchase Order', 'Check' => 'Check', 'PayJunction Invoice' => 'PayJunction Invoice', ]; protected $dates = [ 'created_at', 'updated_at', ]; protected function getPurchaseOrderCopyUrlAttribute() { return $this->purchase_order_copy ? asset('storage/order/' . $this->purchase_order_copy) : $this->purchase_order_copy; } protected function user() { return $this->belongsTo(User::class, 'charged_by_id'); } public function payment(): BelongsTo { return $this->belongsTo(PayJunctionPayments::class, 'payment_id'); } public function order(): BelongsTo { return $this->belongsTo(Order::class, 'order_id'); } } ProductPrice.php 0000644 00000001770 15021222520 0007654 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class ProductPrice extends Model { use HasFactory; protected $guarded = []; protected $dates = [ 'created_at', 'updated_at', 'deleted_at', ]; protected $appends = [ 'product_sketch', ]; public function product() { return $this->belongsTo(Product::class, 'product_id'); } protected function serializeDate(\DateTimeInterface $date) { return $date->format('Y-m-d H:i:s'); } public function combinations() { return $this->hasMany(ProductVariationCombination::class); } public function priceRanges() { return $this->hasMany(ProductVariationRange::class, ''); } protected function getProductSketchMediaAttribute() { return $this->product_sketch ? asset('storage/variation/'.$this->product_sketch) : ""; } } ProductVariationRange.php 0000644 00000000427 15021222520 0011521 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class ProductVariationRange extends Model { use HasFactory; protected $guarded = []; protected $table = 'product_variation_price_ranges'; } Product.php 0000644 00000021556 15021222520 0006675 0 ustar 00 <?php namespace App\Models; use App\Http\Controllers\Traits\MediaUploadingTrait; use \DateTimeInterface; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; use Spatie\MediaLibrary\MediaCollections\Models\Media; use Spatie\Sluggable\HasSlug; use Spatie\Sluggable\SlugOptions; class Product extends Model implements HasMedia { use InteractsWithMedia, MediaUploadingTrait; use HasFactory, HasSlug; public const STATUS_RADIO = [ '1' => 'Enable', '0' => 'Disable', ]; public const DRAFT_RADIO = [ '1' => 'Yes', '0' => 'No', ]; public const PRODUCT_TYPE = [ 'standard' => 'Standard', 'configurable' => 'Configurable', ]; public $table = 'products'; protected $dates = [ 'created_at', 'updated_at', 'deleted_at', ]; protected $casts = [ 'created_at' => 'date:m-d-Y', 'updated_at' => 'date:m-d-Y', ]; protected $appends = [ 'featured_image', 'gallery_images', 'product_sketch', ]; protected $fillable = [ 'vendor_id', 'sku', 'name', 'slug', 'description', 'engraving', 'color_engraving', 'engraving_fee', 'price_from', 'price_to', 'product_sketch', 'status', 'created_at', 'updated_at', 'deleted_at', 'category_id', 'has_variations', 'product_type', 'is_draft', ]; public function getSlugOptions() : SlugOptions { return SlugOptions::create() ->generateSlugsFrom('name') ->saveSlugsTo('slug') ->slugsShouldBeNoLongerThan(100); } public function registerMediaConversions(Media $media = null): void { $this->addMediaConversion('thumb')->fit('crop', 50, 50)->nonQueued(); $this->addMediaConversion('preview')->fit('crop', 120, 120)->nonQueued(); } public function productProductPrices() { return $this->hasMany(ProductPrice::class, 'product_id', 'id'); } public function reviews() { return $this->hasMany(Review::class, 'product_id'); } public function category() { return $this->belongsTo(Category::class, 'category_id'); } public function vendor() { return $this->belongsTo(Vendor::class, 'vendor_id'); } public function getFeaturedImageAttribute() { $file = $this->getMedia('product_featured_image')->last(); if ($file) { $file->url = $file->getUrl(); $file->thumbnail = $file->getUrl('thumb'); $file->preview = $file->getUrl('preview'); } return $file; } protected function getStatusNameAttribute() { return self::STATUS_RADIO[$this->status]; } protected function getProductSketchMediaAttribute() { return $this->product_sketch ? asset('storage/product/'.$this->product_sketch) : ""; } public function getGalleryImagesAttribute() { $files = $this->getMedia('gallery_image'); $files->each(function ($item) { $item->url = $item->getUrl(); $item->thumbnail = $item->getUrl('thumb'); $item->preview = $item->getUrl('preview'); }); return $files; } protected function serializeDate(DateTimeInterface $date) { return $date->format('Y-m-d H:i:s'); } public function scopeActive($query) { return $query->where('status', 1); } public function scopePublished($query) { return $query->where('is_draft', 0); } public function variations() { return $this->hasMany(ProductVariation::class, 'product_id'); } public function prices() { return $this->hasMany(ProductPrice::class); } public function handleVariations($request) { foreach ($request['variations'] as $variation){ $v = ProductVariation::updateOrCreate([ 'product_id' => $this->id, 'variation_id' => $variation, ],[ 'product_id' => $this->id, 'variation_id' => $variation, ]); $v_ids[] = $v->id; } $product_min_price = 0; $product_max_price = 0; $product_price_ids = []; foreach ($request['combinations'] as $combination){ $product_price = ProductPrice::where('supplier_prod_number', $combination['supplier_prod_number'])->first(); if ($product_price) { $product_price->product_id = $this->id; $product_price->vendor_price = $combination['vendor_price'] ?? null; $product_price->shipping_weight = $combination['shipping_weight']; $product_price->length = $combination['length']; $product_price->width = $combination['width']; $product_price->height = $combination['height']; $product_price->save(); } else { $product_price = ProductPrice::create([ 'product_id' => $this->id, 'vendor_price' => $combination['vendor_price'] ?? null, 'supplier_prod_number' => $combination['supplier_prod_number'], 'shipping_weight' => $combination['shipping_weight'], 'length' => $combination['length'], 'width' => $combination['width'], 'height' => $combination['height'], ]); } $product_price_ids[] = $product_price->id; if (isset($combination['product_sketch']) && is_file($combination['product_sketch'])) { $product_price->product_sketch = $this->storePDF($combination['product_sketch'], $product_price->id, 'variation'); $product_price->save(); } $product_variation_combination = []; $price_ranges = []; foreach ($combination['variations'] as $v){ $product_variation_combination[] = [ 'product_id' => $this->id, 'variation_id' => $v, 'product_price_id' => $product_price->id, 'created_at' => now(), 'updated_at' => now(), ]; } $min_price = 0; $max_price = 0; foreach ($combination['price_ranges'] as $range){ $price_ranges[] = [ 'product_id' => $this->id, 'product_price_id' => $product_price->id, 'qty_from' => $range['qty_from'], 'qty_to' => $range['qty_to'], 'price' => $range['price'], 'created_at' => now(), 'updated_at' => now(), ]; $min_price = $min_price == 0 ? $range['price'] : min($range['price'], $min_price); $max_price = $max_price == 0 ? $range['price'] : max($range['price'], $max_price); $product_min_price = $product_min_price == 0 ? $min_price : min($product_min_price, $min_price); $product_max_price = $product_max_price == 0 ? $max_price : max($product_max_price, $max_price); } ProductVariationCombination::where('product_price_id',$product_price->id)->delete(); ProductVariationCombination::insert($product_variation_combination); ProductVariationRange::where('product_price_id',$product_price->id)->delete(); ProductVariationRange::insert($price_ranges); $product_price->min_price = $min_price; $product_price->max_price = $max_price; $product_price->avg_price = ($min_price + $max_price) / 2; $product_price->save(); } //Delete combinations that are not in array while updating product ProductVariationCombination::whereNotIn('product_price_id',$product_price_ids) ->where('product_id', $this->id)->delete(); ProductVariationRange::whereNotIn('product_price_id',$product_price_ids) ->where('product_id', $this->id)->delete(); //To delete the price id that is not included in request array ProductPrice::whereNotIn('id', $product_price_ids) ->where('product_id', $this->id)->delete(); $this->variations()->whereNotIn('id', $v_ids)->delete(); $this->price_from = $product_min_price; $this->price_to = $product_max_price; $this->avg_price = ($product_min_price + $product_max_price) / 2; $this->save(); } } TempProductUrl.php 0000644 00000000327 15021222520 0010177 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class TempProductUrl extends Model { use HasFactory; protected $guarded = []; } PurchaseOrderOrderDetails.php 0000644 00000000724 15021222520 0012317 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; class PurchaseOrderOrderDetails extends Model { use HasFactory; protected $table = "purchase_order_order_details"; protected $guarded = [ '_token', ]; public function order(): BelongsTo { return $this->belongsTo(Order::class, 'order_id'); } } OfficeSupplies.php 0000644 00000003515 15021222520 0010170 0 ustar 00 <?php namespace App\Models; use App\Http\Controllers\Traits\MediaUploadingTrait; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; use Spatie\MediaLibrary\MediaCollections\Models\Media; class OfficeSupplies extends Model implements HasMedia { use HasFactory, InteractsWithMedia, MediaUploadingTrait; protected $table = "office_supplies"; public const STATUS_RADIO = [ '1' => 'Enable', '0' => 'Disable', ]; protected $fillable = [ 'vendor_id', 'name', 'sku', 'description', 'price', 'status', ]; protected $dates = [ 'created_at', 'updated_at', ]; protected $casts = [ 'created_at' => 'date:m-d-Y', 'updated_at' => 'date:m-d-Y', ]; protected $appends = [ 'supply_featured_image', ]; public function registerMediaConversions(Media $media = null): void { $this->addMediaConversion('thumb')->fit('crop', 50, 50)->nonQueued(); $this->addMediaConversion('preview')->fit('crop', 120, 120)->nonQueued(); } public function getSupplyFeaturedImageAttribute() { $file = $this->getMedia('featured_image')->last(); if ($file) { $file->url = $file->getUrl(); $file->thumbnail = $file->getUrl('thumb'); $file->preview = $file->getUrl('preview'); } return $file; } protected function getStatusNameAttribute() { return self::STATUS_RADIO[$this->status]; } public function scopeActive($query) { return $query->where('status', 1); } public function vendor() { return $this->belongsTo(Vendor::class, 'vendor_id', 'id'); } } PurchaseOrder.php 0000644 00000006541 15021222520 0010020 0 ustar 00 <?php namespace App\Models; use Barryvdh\DomPDF\Facade\Pdf; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Support\Facades\Storage; class PurchaseOrder extends Model { use HasFactory; public const PURCHASE_ORDER_STATUS = [ 'Pending' => 'Pending', 'Received' => 'Received', ]; public const PAYMENT_TERMS = [ 'Bank Transfer', 'Check', 'Credit Card', 'Cash', ]; public const SHIPPING_SPEED = [ 'Next day air', 'Second day air', '3 day air', 'Ground shipping', 'Freight shipping', 'Will call', 'Contract Terms', ]; protected $guarded = [ '_token', ]; public const REPORTS_MODE = [ 'previous_month' => 'previousMonth', 'current_month' => 'currentMonth', 'previous_year' => 'previousYear', 'current_year' => 'currentYear', 'all' => 'untilToday', ]; public const REPORTS_MODE_FOR_REPORT = [ 'previous_year' => 'previousYear', 'current_year' => 'currentYear', 'custom' => 'customRange', ]; public function scopePreviousMonth($query) { $start_date = now()->startOfMonth()->subMonth(); $end_date = now()->endOfMonth()->subMonth(); $query->whereBetween('created_at', [$start_date, $end_date]); } public function scopeCurrentMonth($query) { $start_date = now()->startOfMonth(); $end_date = now()->endOfMonth(); $query->whereBetween('created_at', [$start_date, $end_date]); } public function scopePreviousYear($query) { $start_date = now()->startOfYear()->subYear(); $end_date = now()->endOfYear()->subYear(); $query->whereBetween('created_at', [$start_date, $end_date]); } public function scopeCurrentYear($query) { $start_date = now()->startOfYear(); $end_date = now()->endOfYear(); $query->whereBetween('created_at', [$start_date, $end_date]); } public function scopeUntilToday($query) { return $query; } public function product() { return $this->belongsTo(Product::class, 'product_id'); } public function vendor() { return $this->belongsTo(Vendor::class, 'vendor_id'); } public function orderDetails(): HasMany { return $this->hasMany(PurchaseOrderDetails::class, 'purchase_order_id'); } public function user(): BelongsTo { return $this->belongsTo(User::class, 'ordered_by_id'); } public function location(): BelongsTo { return $this->belongsTo(StockLocation::class, 'stock_location_id'); } public function generateAttachment($data) { $pdf = PDF::loadView('partials.po_attachment', [ 'data' => $data, ])->setPaper('A4'); $pdf_name = 'purchase_order_'.$this->order_number . '.pdf'; $file_path = public_path('storage/purchase_orders_attachments/' . $pdf_name); if (!Storage::disk('public')->exists('purchase_orders_attachments')) { Storage::disk('public')->makeDirectory('purchase_orders_attachments'); } $pdf->save($file_path); return $file_path; } } Asset.php 0000644 00000010054 15021240104 0006321 0 ustar 00 <?php namespace App\Models; use Carbon\Carbon; use DateTimeInterface; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; use Spatie\MediaLibrary\MediaCollections\Models\Media; class Asset extends Model implements HasMedia { use InteractsWithMedia, HasFactory; public $table = 'assets'; protected $appends = [ 'asset_image', ]; protected $dates = [ 'asset_expiration_date', 'next_audit_date', 'purchase_date', 'eol_date', 'created_at', 'updated_at', ]; protected $fillable = [ 'organization_id', 'asset_name', 'asset_status_id', 'category_id', 'manufacturer_id', 'supplier_id', 'company_id', 'branch_id', 'qty', 'purchase_cost', 'currency_id', 'notes', 'asset_expiration_date', 'next_audit_date', 'purchase_date', 'eol_date', 'created_at', 'updated_at', ]; protected function serializeDate(DateTimeInterface $date) { return $date->format('Y-m-d H:i:s'); } public function registerMediaConversions(Media $media = null): void { $this->addMediaConversion('thumb')->fit('crop', 100, 100); $this->addMediaConversion('preview')->fit('crop', 200, 200); } public function organization() { return $this->belongsTo(Organization::class, 'organization_id'); } public function asset_status() { return $this->belongsTo(Status::class, 'asset_status_id'); } public function category() { return $this->belongsTo(Category::class, 'category_id'); } public function manufacturer() { return $this->belongsTo(Manufacturer::class, 'manufacturer_id'); } public function supplier() { return $this->belongsTo(Supplier::class, 'supplier_id'); } public function company() { return $this->belongsTo(Company::class, 'company_id'); } public function branch() { return $this->belongsTo(Branch::class, 'branch_id'); } public function getAssetImageAttribute() { $file = $this->getMedia('asset_image')->last(); if ($file) { $file->url = $file->getUrl(); $file->thumbnail = $file->getUrl('thumb'); $file->preview = $file->getUrl('preview'); } return $file; } public function getAssetExpirationDateAttribute($value) { return $value ? Carbon::parse($value)->format(config('panel.date_format')) : null; } public function setAssetExpirationDateAttribute($value) { $this->attributes['asset_expiration_date'] = $value ? Carbon::createFromFormat(config('panel.date_format'), $value)->format('Y-m-d') : null; } public function getNextAuditDateAttribute($value) { return $value ? Carbon::parse($value)->format(config('panel.date_format')) : null; } public function setNextAuditDateAttribute($value) { $this->attributes['next_audit_date'] = $value ? Carbon::createFromFormat(config('panel.date_format'), $value)->format('Y-m-d') : null; } public function getPurchaseDateAttribute($value) { return $value ? Carbon::parse($value)->format(config('panel.date_format')) : null; } public function setPurchaseDateAttribute($value) { $this->attributes['purchase_date'] = $value ? Carbon::createFromFormat(config('panel.date_format'), $value)->format('Y-m-d') : null; } public function getEolDateAttribute($value) { return $value ? Carbon::parse($value)->format(config('panel.date_format')) : null; } public function setEolDateAttribute($value) { $this->attributes['eol_date'] = $value ? Carbon::createFromFormat(config('panel.date_format'), $value)->format('Y-m-d') : null; } public function currency() { return $this->belongsTo(Currency::class, 'currency_id'); } } AssetTag.php 0000644 00000001504 15021240104 0006755 0 ustar 00 <?php namespace App\Models; use DateTimeInterface; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class AssetTag extends Model { use HasFactory; public $table = 'asset_tags'; protected $dates = [ 'created_at', 'updated_at', ]; protected $fillable = [ 'organization_id', 'asset_id', 'tag_name', 'code', 'serial', 'created_at', 'updated_at', ]; protected function serializeDate(DateTimeInterface $date) { return $date->format('Y-m-d H:i:s'); } public function organization() { return $this->belongsTo(Organization::class, 'organization_id'); } public function asset() { return $this->belongsTo(Asset::class, 'asset_id'); } } Branch.php 0000644 00000001770 15021240104 0006444 0 ustar 00 <?php namespace App\Models; use App\Models\Scopes\UserOrganization; use DateTimeInterface; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Branch extends Model { use HasFactory; public $table = 'branches'; protected $dates = [ 'created_at', 'updated_at', ]; protected $fillable = [ 'organization_id', 'company_id', 'name', 'email', 'contact_number', 'address', 'created_at', 'updated_at', ]; protected static function booted(): void { static::addGlobalScope(new UserOrganization); } protected function serializeDate(DateTimeInterface $date) { return $date->format('Y-m-d H:i:s'); } public function organization() { return $this->belongsTo(Organization::class, 'organization_id'); } public function company() { return $this->belongsTo(Company::class, 'company_id'); } } Scopes/UserOrganization.php 0000644 00000001035 15021240104 0012000 0 ustar 00 <?php namespace App\Models\Scopes; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Scope; class UserOrganization implements Scope { /** * Apply the scope to a given Eloquent query builder. */ public function apply(Builder $builder, Model $model): void { if (auth()->user()) { $builder->where(function ($query) { $query->where('organization_id', auth()->user()->organization_id); }); } } } Country.php 0000644 00000001046 15021240104 0006706 0 ustar 00 <?php namespace App\Models; use DateTimeInterface; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Country extends Model { use HasFactory; public $table = 'countries'; protected $dates = [ 'created_at', 'updated_at', ]; protected $fillable = [ 'name', 'short_code', 'created_at', 'updated_at', ]; protected function serializeDate(DateTimeInterface $date) { return $date->format('Y-m-d H:i:s'); } } Company.php 0000644 00000003256 15021240104 0006656 0 ustar 00 <?php namespace App\Models; use App\Models\Scopes\UserOrganization; use DateTimeInterface; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; use Spatie\MediaLibrary\MediaCollections\Models\Media; class Company extends Model implements HasMedia { use InteractsWithMedia, HasFactory; public $table = 'companies'; protected $appends = [ 'logo', ]; protected $dates = [ 'created_at', 'updated_at', ]; protected $fillable = [ 'organization_id', 'name', 'contact_number', 'created_at', 'updated_at', ]; protected static function booted(): void { static::addGlobalScope(new UserOrganization); } protected function serializeDate(DateTimeInterface $date) { return $date->format('Y-m-d H:i:s'); } public function branches() { return $this->hasMany(Branch::class, 'company_id'); } public function registerMediaConversions(Media $media = null): void { $this->addMediaConversion('thumb')->fit('crop', 100, 100); $this->addMediaConversion('preview')->fit('crop', 200, 200); } public function organization() { return $this->belongsTo(Organization::class, 'organization_id'); } public function getLogoAttribute() { $file = $this->getMedia('logo')->last(); if ($file) { $file->url = $file->getUrl(); $file->thumbnail = $file->getUrl('thumb'); $file->preview = $file->getUrl('preview'); } return $file; } } Department.php 0000644 00000002130 15021240104 0007341 0 ustar 00 <?php namespace App\Models; use App\Models\Scopes\UserOrganization; use DateTimeInterface; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Department extends Model { use HasFactory; public $table = 'departments'; protected $dates = [ 'created_at', 'updated_at', ]; protected $fillable = [ 'organization_id', 'company_id', 'name', 'contact_number', 'manager_id', 'created_at', 'updated_at', ]; protected static function booted(): void { static::addGlobalScope(new UserOrganization); } protected function serializeDate(DateTimeInterface $date) { return $date->format('Y-m-d H:i:s'); } public function organization() { return $this->belongsTo(Organization::class, 'organization_id'); } public function company() { return $this->belongsTo(Company::class, 'company_id'); } public function manager() { return $this->belongsTo(User::class, 'manager_id'); } } Supplier.php 0000644 00000003722 15021240104 0007051 0 ustar 00 <?php namespace App\Models; use App\Models\Scopes\UserOrganization; use DateTimeInterface; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; use Spatie\MediaLibrary\MediaCollections\Models\Media; class Supplier extends Model implements HasMedia { use InteractsWithMedia, HasFactory; public $table = 'suppliers'; protected $appends = [ 'logo', ]; public const STATUS_RADIO = [ '1' => 'Active', '0' => 'Inactive', ]; protected $dates = [ 'created_at', 'updated_at', ]; protected $fillable = [ 'organization_id', 'contact_name', 'contact_email', 'contact_number', 'address_line_1', 'address_line_2', 'city', 'state', 'zip_code', 'country_id', 'url', 'status', 'created_at', 'updated_at', ]; protected static function booted(): void { static::addGlobalScope(new UserOrganization()); } protected function serializeDate(DateTimeInterface $date) { return $date->format('Y-m-d H:i:s'); } public function registerMediaConversions(Media $media = null): void { $this->addMediaConversion('thumb')->fit('crop', 100, 100); $this->addMediaConversion('preview')->fit('crop', 200, 200); } public function organization() { return $this->belongsTo(Organization::class, 'organization_id'); } public function country() { return $this->belongsTo(Country::class, 'country_id'); } public function getLogoAttribute() { $file = $this->getMedia('logo')->last(); if ($file) { $file->url = $file->getUrl(); $file->thumbnail = $file->getUrl('thumb'); $file->preview = $file->getUrl('preview'); } return $file; } } MaintenanceSchedule.php 0000644 00000002216 15021240104 0011142 0 ustar 00 <?php namespace App\Models; use App\Models\Scopes\UserOrganization; use DateTimeInterface; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class MaintenanceSchedule extends Model { use HasFactory; public $table = 'maintenance_schedules'; protected $dates = [ 'created_at', 'updated_at', ]; protected $fillable = [ 'organization_id', 'asset_id', 'maintenance_type', 'scheduled_date', 'completion_date', 'status', 'frequency', 'interval', 'cost', 'assigned_to', 'next_scheduled_date', 'created_at', 'updated_at', ]; protected static function booted(): void { static::addGlobalScope(new UserOrganization); } protected function serializeDate(DateTimeInterface $date) { return $date->format('Y-m-d H:i:s'); } public function organization() { return $this->belongsTo(Organization::class, 'organization_id'); } public function asset() { return $this->belongsTo(Asset::class, 'asset_id'); } } Currency.php 0000644 00000001347 15021240104 0007041 0 ustar 00 <?php namespace App\Models; use App\Models\Scopes\UserOrganization; use DateTimeInterface; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Currency extends Model { use HasFactory; public $table = 'currencies'; protected $dates = [ 'created_at', 'updated_at', ]; protected $fillable = [ 'name', 'code', 'symbol', 'organization_id', 'created_at', 'updated_at', ]; protected static function booted(): void { static::addGlobalScope(new UserOrganization); } protected function serializeDate(DateTimeInterface $date) { return $date->format('Y-m-d H:i:s'); } } CompanyUser.php 0000644 00000000332 15021240104 0007505 0 ustar 00 <?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class CompanyUser extends Model { use HasFactory; public $table = 'company_user'; } Manufacturer.php 0000644 00000003426 15021240104 0007703 0 ustar 00 <?php namespace App\Models; use App\Models\Scopes\UserOrganization; use DateTimeInterface; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; use Spatie\MediaLibrary\MediaCollections\Models\Media; class Manufacturer extends Model implements HasMedia { use InteractsWithMedia, HasFactory; public $table = 'manufacturers'; protected $appends = [ 'logo', ]; public const STATUS_RADIO = [ '1' => 'Active', '0' => 'Inactive', ]; protected $dates = [ 'created_at', 'updated_at', ]; protected $fillable = [ 'organization_id', 'name', 'support_url', 'support_contact_number', 'support_email', 'warranty_lookup_url', 'status', 'created_at', 'updated_at', ]; protected static function booted(): void { static::addGlobalScope(new UserOrganization); } protected function serializeDate(DateTimeInterface $date) { return $date->format('Y-m-d H:i:s'); } public function registerMediaConversions(Media $media = null): void { $this->addMediaConversion('thumb')->fit('crop', 100, 100); $this->addMediaConversion('preview')->fit('crop', 200, 200); } public function organization() { return $this->belongsTo(Organization::class, 'organization_id'); } public function getLogoAttribute() { $file = $this->getMedia('logo')->last(); if ($file) { $file->url = $file->getUrl(); $file->thumbnail = $file->getUrl('thumb'); $file->preview = $file->getUrl('preview'); } return $file; } } Organization.php 0000644 00000003502 15021240104 0007706 0 ustar 00 <?php namespace App\Models; use Carbon\Carbon; use DateTimeInterface; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Spatie\MediaLibrary\HasMedia; use Spatie\MediaLibrary\InteractsWithMedia; use Spatie\MediaLibrary\MediaCollections\Models\Media; class Organization extends Model implements HasMedia { use InteractsWithMedia, HasFactory; public $table = 'organizations'; protected $appends = [ 'logo', ]; public const STATUS_RADIO = [ '1' => 'Active', '0' => 'Inactive', ]; protected $dates = [ 'date_expiration', 'created_at', 'updated_at', ]; protected $fillable = [ 'name', 'email', 'contact_number', 'address_line_1', 'address_line_2', 'status', 'date_expiration', 'created_at', 'updated_at', ]; protected function serializeDate(DateTimeInterface $date) { return $date->format('Y-m-d H:i:s'); } public function registerMediaConversions(Media $media = null): void { $this->addMediaConversion('thumb')->fit('crop', 100, 100); $this->addMediaConversion('preview')->fit('crop', 200, 200); } public function organizationRoles() { return $this->hasMany(Role::class, 'organization_id', 'id'); } public function getLogoAttribute() { $file = $this->getMedia('logo')->last(); if ($file) { $file->url = $file->getUrl(); $file->thumbnail = $file->getUrl('thumb'); $file->preview = $file->getUrl('preview'); } return $file; } public function getDateExpirationAttribute($value) { return $value ? Carbon::parse($value)->format(config('panel.date_format')) : null; } }
| ver. 1.4 |
Github
|
.
| PHP 8.1.29 | Генерация страницы: 0 |
proxy
|
phpinfo
|
Настройка