
    si                        d Z ddlmZ ddlmZ ddlmZmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZ dd	lmZ dd
lmZmZ ddlmZmZmZ ddlmZ ddlmZ ddlmZ  eed       e ed      d       G d de                    Z  eed       e ed      d       G d de                    Z! eed       e ed      d       G d de                    Z" eed       e ed      d       G d de                    Z#y)z>
This page is handle the payslip automation page in settings.
    )Any)messages)HttpResponseHttpResponseRedirect)get_object_or_404)reverse)method_decorator)gettext_lazy)View)login_requiredpermission_required)HorillaFormViewHorillaListViewHorillaNavView)PayslipAutoGenerateFilter)PayslipAutoGenerateForm)PayslipAutoGeneratedispatch)namez payroll.view_PayslipAutoGenerate)permc                        e Zd ZdZdeddf fdZeZeZ	 e
d      df e
d      d	f e
d
      dfgZddiZddddddddgZdZ xZS )PaySlipAutomationListViewz
    List view of the page
    kwargsreturnNc                 R    t        |   di | d| _        t        d      | _        y )Npay_slip_idpay-slip-automation-list )super__init__view_idr   
search_urlselfr   	__class__s     B/var/www/python-projects/worksol/payroll/cbv/payslip_automation.pyr    z"PaySlipAutomationListView.__init__#   s)    "6" %!"<=    zPayslip creation dateget_generate_day_displayCompanyget_companyz	Is activeis_active_colzH
                   style = "width:200px !important"
                   Editzcreate-outlinea,  
                    class="oh-btn oh-btn--light-bkg w-50"
                    hx-get="{get_update_url}?instance_ids={ordered_ids}"
                    hx-target="#genericModalBody"
                    data-toggle="oh-modal-toggle"
                    data-target="#genericModal"
                    )actioniconattrsDeleteztrash-outlineaW  
                    class="oh-btn oh-btn--danger-outline oh-btn--light-bkg w-50"
                    hx-confirm="Are you sure you want to delete this payslip auto generate?"
                    hx-target="#autoPayslipTr{get_instance_id}"
                    hx-post="{get_delete_url}"
                    hx-swap="delete"
                    zG
                id = "autoPayslipTr{get_instance_id}"
                )__name__
__module____qualname____doc__r   r    r   modelr   filter_class_columnsheader_attrsactions	row_attrs__classcell__r%   s   @r&   r   r      s    
> > >  E,L 
"	#%?@	
9}%	
;)G 	# %L $
	
 #
	
G2Ir'   r   c                   N     e Zd ZdZdeddf fdZ ed      Z e       Z	dZ
 xZS )PaySlipAutomationNavz
    Nav bar
    r   r   Nc                 l    t        |   di | t        d      | _        dt        d       d| _        y )Nr   a  
                            onclick = "event.stopPropagation();"
                            data-toggle="oh-modal-toggle"
                            data-target="#genericModal"
                            hx-target="#genericModalBody"
                            hx-get="zpay-slip-automation-createz"
                            r   )r   r    r   r"   create_attrsr#   s     r&   r    zPaySlipAutomationNav.__init__c   sC    "6"!"<=!%
 &--I%J$K L r'   zPayslip Automationz#listContainer)r1   r2   r3   r4   r   r    r7   	nav_titler   filter_instancesearch_swap_targetr<   r=   s   @r&   r?   r?   Z   s6    
	  	  	  &'I/1O)r'   r?   z"payroll.change_PayslipAutoGeneratec                   N     e Zd ZdZeZeZ ed      Z	 fdZ
dedef fdZ xZS )PaySlipAutomationFormViewz
    Create and edit form
    zCreate Auto Payslip Generatec                     t        |   di |}| j                  j                  j                  rt        d      | j                  _        |S )z?
        Get context data for rendering the form view.
        zUpdate Auto Payslip Generater   )r   get_context_dataforminstancepkr7   
form_classverbose_name)r$   r   contextr%   s      r&   rH   z*PaySlipAutomationFormView.get_context_data   sA     '*4V499  +,-K+LDOO(r'   rI   r   c                    | j                   j                  j                  r | j                   j                  j                  nd}|j                         ru|j                  j                  rt        d| d      }nt        d| d      }|j                          t        j                  | j                  |       | j                         S t        | 1  |      S )z
        Handle a valid form submission.

        If the form is valid, save the instance and display a success message.
        zAll companyzPayslip Auto generate for z created successfully )rI   rJ   
company_idis_validrK   r7   saver   successrequestr   r   
form_valid)r$   rI   companymessager%   s       r&   rU   z$PaySlipAutomationFormView.form_valid   s     yy!!,, II)) 	
 ==?}}0	9OP 0	9OP IIKT\\73$$&&w!$''r'   )r1   r2   r3   r4   r   r5   r   rL   r7   new_display_titlerH   r   rU   r<   r=   s   @r&   rF   rF   s   s>    
  E(J89(6 (< ( (r'   rF   z"payroll.delete_PayslipAutoGeneratec                       e Zd ZdZd Zy)DeleteAutoPayslipViewz
    Handles deletion of a PayslipAutoGenerate object.

    Deletes the object if 'auto_generate' is False, else shows a message.
    Redirects to the referring page or root URL.
    c                 r   t        t        |      }|j                  sW|j                  r|j                  n
t	        d      }|j                          t        j                  |t	        d| d             nt        j                  |t	        d             t        |j                  j                  dd            S )zG
        Deletes the PayslipAutoGenerate object and redirects.
        )idzAll companieszPayslip auto generate for z deleted successfully.z1Active 'Payslip auto generate' cannot be deleted.HTTP_REFERER/)r   r   auto_generaterP   r7   deleter   rS   infor   METAget)r$   rT   auto_idauto_paysliprV   s        r&   postzDeleteAutoPayslipView.post   s     ))<I))  ** ''' 
 !.wi7MNO
 MMNO $GLL$4$4^S$IJJr'   N)r1   r2   r3   r4   rf   r   r'   r&   rZ   rZ      s    
Kr'   rZ   N)$r4   typingr   django.contribr   django.httpr   r   django.shortcutsr   django.urlsr   django.utils.decoratorsr	   django.utils.translationr
   r7   django.viewsr   horilla_views.cbv_methodsr   r   horilla_views.generic.cbv.viewsr   r   r   payroll.filtersr   payroll.forms.component_formsr   payroll.models.modelsr   r   r?   rF   rZ   r   r'   r&   <module>rt      s)    # : .  4 6  I 
 6 A 5 .z2?@z6 6 36x .z2?@z*> * 3** .z2AB)( )( 3)(X .z2ABKD K 3Kr'   