@use('App\Services\Date') @extends('companyuser::layouts.master') @section('title', __('sales::invoices.create_invoice')) @section('extra-styles') @if(app()->getLocale()=='en') @else @endif @endsection @section('breadcrumb') @endsection @section('content')
@csrf
@php $showInvoiceTypeSelector = false; if (!request()->query('type') && array_keys(request()->query()) && is_int(array_keys(request()->query())[0])) { request()->merge(['type' => array_keys(request()->query())[0]]); } if(!isset(request()->query()['type'])){ $showInvoiceTypeSelector = true; if($companyInfo->zatca_comply){ // Invoice type is null (we need to get it from the settings model) if($settings->invoice_type == \Modules\Sales\Enums\Zatca\CertificateInvoiceTypesEnum::STANDARD_AND_SIMPLIFIED){ $invoiceTaxableTypes = \Modules\Sales\Enums\InvoiceTypesEnum::TAXABLE_TYPES; }else{ $invoiceTaxableTypes = [\Modules\Sales\Enums\InvoiceTypesEnum::SIMPLIFIED_TAX_INVOICE]; } $queryType = ''; }else{ if($settings){ if($settings->taxable){ $invoiceTaxableTypes = \Modules\Sales\Enums\InvoiceTypesEnum::TAXABLE_TYPES; $queryType = \Modules\Sales\Enums\InvoiceTypesEnum::SIMPLIFIED_TAX_INVOICE; }else{ $invoiceTaxableTypes = [\Modules\Sales\Enums\InvoiceTypesEnum::SALES_INVOICE]; $queryType = \Modules\Sales\Enums\InvoiceTypesEnum::SALES_INVOICE; } }else{ $invoiceTaxableTypes = [\Modules\Sales\Enums\InvoiceTypesEnum::SALES_INVOICE]; $queryType = \Modules\Sales\Enums\InvoiceTypesEnum::SALES_INVOICE; } } }else{ $queryType = request()->query()['type']; } $isSimplifiedType = false; if (in_array($queryType, Modules\Sales\Enums\InvoiceTypesEnum::SIMPLIFIED_TYPES) && $isNotSimplifiedOnlyInvoiceCompany) { $isSimplifiedType = true; } @endphp @if ($isSimplifiedType && $companyInfo->zatca_comply)

{{__('sales::invoices.note_for_simplified_invoice_b2b_client')}}

@endif @if (str_contains(request()->getRequestUri(), 'create-invoice-debit-from-invoice')) @endif {{-- Hidden field to keep track of requisition conversion --}} @php $convertedRequisitionId = old('converted_requisition_id', isset($invoice) ? $invoice->requisition_id : ''); @endphp @if ($convertedRequisitionId) @endif @if( !isset($currentFiscalYearId))
@lang('superadmin::Dashboard.Please set your ')  @lang('settings::general_settings.accounting settings')   @lang('superadmin::Dashboard.to start adding accounting transactions')
@endif
{{-- @include('companyuser::errors.all')--}} @include('companyuser::errors.operation-locked') @include('companyuser::errors.lists') @error('remaining') @enderror @error('attachment_id') @enderror @if($remaining)
@if(isset($taxableUser) && $taxableUser && !request('type') || $showInvoiceTypeSelector)
@error('type') @enderror
@else @endif
@error('code') @enderror
( @lang('optional') )
@error('description')

{{ $message }}

@enderror
*
@php $selectedCustomerId = old('customer') ?? ($invoice ? $invoice->customer_id : null) ?? request('customer') ?? request('customer_id'); @endphp
@error('customer') @enderror
@error('payment_date') @enderror @error('current_fiscal_year_id') @enderror
@error('time') @enderror
@php // Determine the pre-selected cost center id $preloadedCostCenterId = old('cost_center_id', isset($cost_center_id) ? $cost_center_id : ($invoice ? $invoice->cost_center_id : '')); $hasMainCostCenterPermission = auth()->user()->can('cost-center.main-center.create'); $shouldSelectMainCostCenter = empty($preloadedCostCenterId) && $hasMainCostCenterPermission; @endphp
@if(!empty($disableCostCenter)) @endif @error('cost_center_id')

{{ $message }}

@enderror @if(isFeatureActive(Modules\Settings\Enums\FeaturesEnum::INVENTORY))

{{ __('validation.change_warning', ['field' => __('products::cost_center.Cost Center')]) }}

@endif
*
@php // Replicate the original select logic: if (old('payment_term')) { $oldPaymentTermId = old('payment_term'); } elseif ($invoice && $invoice->payment_account) { $oldPaymentTermId = $invoice->payment_term_id ?? null; } elseif (old('payment_account')) { $oldPaymentTermId = 'cash'; } else { $oldPaymentTermId = null; } @endphp
@error('payment_term') @enderror
@if (!str_contains(request()->getRequestUri(), 'debit') || !isset($invoice->id))
@error('supply_date') @enderror
@endif

@lang('sales::invoices.Customer Details'):

@lang('sales::invoices.Phone'):
@lang('sales::invoices.Email'):
@lang('sales::invoices.Outstanding Balance'):

@lang('sales::invoices.validate_minimum_quantity_message')


@error('products.*')

{!! $message !!}

@enderror @error('other_fees_details.*')

{!! $message !!}

@enderror @error('products')

{!! $message !!}

@enderror @error('labor_fee')

{{ $message }}

@enderror
@if( $customFields->count() )
@foreach($customFields as $key=>$field)
@if($field['type']=='checkbox') @else @endif
@endforeach
@endif
@error('zatca_errors') @enderror
@if($companyInfo->zatca_comply)

@lang('sales::invoices.toc_zatca_note')

@endif
@error('terms') @enderror
@if($companyInfo->zatca_comply)

@lang('sales::invoices.notes_zatca_note')

@endif
@error('notes') @enderror
@if(!old('attachment_id') && !request('attachment_id')) @endif
@if($invoice && $invoice->deletedProducts) {{---------------- popup for displaying bill deleted products ---------------------}} @endif
@else @include('info.limit_reached') @endif
@endsection @section('extra_scripts') @include('sales::scripts.get_products_sales_script')