File size: 7,623 Bytes
2059161
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
class DocWizard extends HTMLElement {
  connectedCallback() {
    this.attachShadow({ mode: 'open' });
    this.shadowRoot.innerHTML = `
      <style>
        :host {
          display: block;
          max-width: 800px;
          margin: 2rem auto;
          padding: 1.5rem;
          background: white;
          border-radius: 8px;
          box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        h2 {
          color: #4f46e5;
          margin-bottom: 1.5rem;
          text-align: center;
        }
        .form-grid {
          display: grid;
          grid-template-columns: repeat(2, 1fr);
          gap: 1rem;
        }
        .form-group {
          margin-bottom: 1rem;
        }
        label {
          display: block;
          margin-bottom: 0.5rem;
          font-weight: 500;
          color: #374151;
        }
        input, select, textarea {
          width: 100%;
          padding: 0.5rem;
          border: 1px solid #d1d5db;
          border-radius: 4px;
          font-size: 1rem;
        }
        .full-width {
          grid-column: 1 / -1;
        }
        button {
          background: #4f46e5;
          color: white;
          border: none;
          padding: 0.75rem 1.5rem;
          border-radius: 4px;
          cursor: pointer;
          font-size: 1rem;
          transition: background 0.2s;
        }
        button:hover {
          background: #4338ca;
        }
        .actions {
          display: flex;
          justify-content: flex-end;
          gap: 1rem;
          margin-top: 1.5rem;
        }
        .error {
          color: #dc2626;
          margin-top: 0.25rem;
          font-size: 0.875rem;
        }
      </style>
      <h2>Document Generator Wizard</h2>
      <form id="docForm">
        <div class="form-grid">
          <div class="form-group">
            <label for="agreement_date">Agreement Date</label>
            <input type="date" id="agreement_date" required>
          </div>
          
          <div class="form-group">
            <label for="territory">Territory</label>
            <input type="text" id="territory" value="State of Qatar" required>
          </div>
          
          <div class="form-group">
            <label for="vendor_name_en">Vendor Name (English)</label>
            <input type="text" id="vendor_name_en" required>
          </div>
          
          <div class="form-group">
            <label for="vendor_name_ar">Vendor Name (Arabic)</label>
            <input type="text" id="vendor_name_ar" dir="rtl" required>
          </div>
          
          <div class="form-group">
            <label for="vendor_cr">Vendor CR Number</label>
            <input type="text" id="vendor_cr" required>
          </div>
          
          <div class="form-group">
            <label for="delivery_mode">Delivery Mode</label>
            <select id="delivery_mode" required>
              <option value="aldobi_delivery">Aldobi Delivery (30% commission)</option>
              <option value="vendor_delivery">Vendor Delivery (15% commission)</option>
            </select>
          </div>
          
          <div class="form-group">
            <label for="commission_pct">Commission % (override)</label>
            <input type="number" id="commission_pct" min="0" max="100">
          </div>
          
          <div class="form-group full-width">
            <label for="vendor_address">Vendor Address</label>
            <textarea id="vendor_address" rows="2"></textarea>
          </div>
          
          <div class="form-group">
            <label for="start_date">Start Date</label>
            <input type="date" id="start_date" required>
          </div>
          
          <div class="form-group">
            <label for="term_months">Contract Duration (months)</label>
            <input type="number" id="term_months" value="12" min="1" required>
          </div>
          
          <div class="form-group">
            <label for="auto_renewal">Auto-Renewal</label>
            <select id="auto_renewal">
              <option value="Yes">Yes</option>
              <option value="No" selected>No</option>
            </select>
          </div>
          
          <div class="form-group">
            <label for="payment_terms">Payment Terms</label>
            <input type="text" id="payment_terms" value="Net 15–30 days (preferred first week of month)">
          </div>
        </div>
        
        <h3>Signatory Details</h3>
        <div class="form-grid">
          <div class="form-group">
            <label for="aldobi_sign_name">Aldobi Signatory Name</label>
            <input type="text" id="aldobi_sign_name" required>
          </div>
          
          <div class="form-group">
            <label for="aldobi_sign_title">Aldobi Signatory Title</label>
            <input type="text" id="aldobi_sign_title" placeholder="e.g., Chairman">
          </div>
          
          <div class="form-group">
            <label for="vendor_sign_name">Vendor Signatory Name</label>
            <input type="text" id="vendor_sign_name" required>
          </div>
          
          <div class="form-group">
            <label for="vendor_sign_title">Vendor Signatory Title</label>
            <input type="text" id="vendor_sign_title">
          </div>
        </div>
        
        <div class="actions">
          <button type="button" id="generateBtn">Generate Document</button>
          <button type="reset">Reset Form</button>
        </div>
      </form>
    `;

    this.shadowRoot.getElementById('generateBtn').addEventListener('click', this.handleGenerate.bind(this));
  }

  handleGenerate() {
    const form = this.shadowRoot.getElementById('docForm');
    if (!form.checkValidity()) {
      form.reportValidity();
      return;
    }

    const formData = {
      agreement_date: this.shadowRoot.getElementById('agreement_date').value,
      territory: this.shadowRoot.getElementById('territory').value,
      vendor_name_en: this.shadowRoot.getElementById('vendor_name_en').value,
      vendor_name_ar: this.shadowRoot.getElementById('vendor_name_ar').value,
      vendor_cr: this.shadowRoot.getElementById('vendor_cr').value,
      vendor_address: this.shadowRoot.getElementById('vendor_address').value,
      delivery_mode: this.shadowRoot.getElementById('delivery_mode').value,
      commission_pct: this.shadowRoot.getElementById('commission_pct').value,
      payment_terms: this.shadowRoot.getElementById('payment_terms').value,
      start_date: this.shadowRoot.getElementById('start_date').value,
      term_months: this.shadowRoot.getElementById('term_months').value,
      auto_renewal: this.shadowRoot.getElementById('auto_renewal').value,
      aldobi_sign_name: this.shadowRoot.getElementById('aldobi_sign_name').value,
      aldobi_sign_title: this.shadowRoot.getElementById('aldobi_sign_title').value,
      vendor_sign_name: this.shadowRoot.getElementById('vendor_sign_name').value,
      vendor_sign_title: this.shadowRoot.getElementById('vendor_sign_title').value,
      enable_social_media: 'true',
      enable_data_minimization: 'true',
      enable_delay_policy: 'true',
      enable_dispute_policy: 'true'
    };

    // Apply business rules for default values
    if (!formData.commission_pct) {
      formData.commission_pct = formData.delivery_mode === 'aldobi_delivery' ? '30' : '15';
    }

    // Dispatch custom event with form data
    this.dispatchEvent(new CustomEvent('generate-document', {
      bubbles: true,
      composed: true,
      detail: formData
    }));
  }
}

customElements.define('doc-wizard', DocWizard);